mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-15 00:56:46 +07:00
69111bac42
This still has not been merged and now powerpc is the only arch that does not have this change. Sorry about missing linuxppc-dev before. V2->V2 - Fix up to work against 3.18-rc1 __get_cpu_var() is used for multiple purposes in the kernel source. One of them is address calculation via the form &__get_cpu_var(x). This calculates the address for the instance of the percpu variable of the current processor based on an offset. Other use cases are for storing and retrieving data from the current processors percpu area. __get_cpu_var() can be used as an lvalue when writing data or on the right side of an assignment. __get_cpu_var() is defined as : __get_cpu_var() always only does an address determination. However, store and retrieve operations could use a segment prefix (or global register on other platforms) to avoid the address calculation. this_cpu_write() and this_cpu_read() can directly take an offset into a percpu area and use optimized assembly code to read and write per cpu variables. This patch converts __get_cpu_var into either an explicit address calculation using this_cpu_ptr() or into a use of this_cpu operations that use the offset. Thereby address calculations are avoided and less registers are used when code is generated. At the end of the patch set all uses of __get_cpu_var have been removed so the macro is removed too. The patch set includes passes over all arches as well. Once these operations are used throughout then specialized macros can be defined in non -x86 arches as well in order to optimize per cpu access by f.e. using a global register that may be set to the per cpu base. Transformations done to __get_cpu_var() 1. Determine the address of the percpu instance of the current processor. DEFINE_PER_CPU(int, y); int *x = &__get_cpu_var(y); Converts to int *x = this_cpu_ptr(&y); 2. Same as #1 but this time an array structure is involved. DEFINE_PER_CPU(int, y[20]); int *x = __get_cpu_var(y); Converts to int *x = this_cpu_ptr(y); 3. Retrieve the content of the current processors instance of a per cpu variable. DEFINE_PER_CPU(int, y); int x = __get_cpu_var(y) Converts to int x = __this_cpu_read(y); 4. Retrieve the content of a percpu struct DEFINE_PER_CPU(struct mystruct, y); struct mystruct x = __get_cpu_var(y); Converts to memcpy(&x, this_cpu_ptr(&y), sizeof(x)); 5. Assignment to a per cpu variable DEFINE_PER_CPU(int, y) __get_cpu_var(y) = x; Converts to __this_cpu_write(y, x); 6. Increment/Decrement etc of a per cpu variable DEFINE_PER_CPU(int, y); __get_cpu_var(y)++ Converts to __this_cpu_inc(y) Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> CC: Paul Mackerras <paulus@samba.org> Signed-off-by: Christoph Lameter <cl@linux.com> [mpe: Fix build errors caused by set/or_softirq_pending(), and rework assignment in __set_breakpoint() to use memcpy().] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
167 lines
4.0 KiB
C
167 lines
4.0 KiB
C
/*
|
|
* Copyright (C) 2006 Mike Kravetz IBM Corporation
|
|
*
|
|
* Hypervisor Call Instrumentation
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/debugfs.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/cpumask.h>
|
|
#include <asm/hvcall.h>
|
|
#include <asm/firmware.h>
|
|
#include <asm/cputable.h>
|
|
#include <asm/trace.h>
|
|
#include <asm/machdep.h>
|
|
|
|
DEFINE_PER_CPU(struct hcall_stats[HCALL_STAT_ARRAY_SIZE], hcall_stats);
|
|
|
|
/*
|
|
* Routines for displaying the statistics in debugfs
|
|
*/
|
|
static void *hc_start(struct seq_file *m, loff_t *pos)
|
|
{
|
|
if ((int)*pos < (HCALL_STAT_ARRAY_SIZE-1))
|
|
return (void *)(unsigned long)(*pos + 1);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static void *hc_next(struct seq_file *m, void *p, loff_t * pos)
|
|
{
|
|
++*pos;
|
|
|
|
return hc_start(m, pos);
|
|
}
|
|
|
|
static void hc_stop(struct seq_file *m, void *p)
|
|
{
|
|
}
|
|
|
|
static int hc_show(struct seq_file *m, void *p)
|
|
{
|
|
unsigned long h_num = (unsigned long)p;
|
|
struct hcall_stats *hs = m->private;
|
|
|
|
if (hs[h_num].num_calls) {
|
|
if (cpu_has_feature(CPU_FTR_PURR))
|
|
seq_printf(m, "%lu %lu %lu %lu\n", h_num<<2,
|
|
hs[h_num].num_calls,
|
|
hs[h_num].tb_total,
|
|
hs[h_num].purr_total);
|
|
else
|
|
seq_printf(m, "%lu %lu %lu\n", h_num<<2,
|
|
hs[h_num].num_calls,
|
|
hs[h_num].tb_total);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct seq_operations hcall_inst_seq_ops = {
|
|
.start = hc_start,
|
|
.next = hc_next,
|
|
.stop = hc_stop,
|
|
.show = hc_show
|
|
};
|
|
|
|
static int hcall_inst_seq_open(struct inode *inode, struct file *file)
|
|
{
|
|
int rc;
|
|
struct seq_file *seq;
|
|
|
|
rc = seq_open(file, &hcall_inst_seq_ops);
|
|
seq = file->private_data;
|
|
seq->private = file_inode(file)->i_private;
|
|
|
|
return rc;
|
|
}
|
|
|
|
static const struct file_operations hcall_inst_seq_fops = {
|
|
.open = hcall_inst_seq_open,
|
|
.read = seq_read,
|
|
.llseek = seq_lseek,
|
|
.release = seq_release,
|
|
};
|
|
|
|
#define HCALL_ROOT_DIR "hcall_inst"
|
|
#define CPU_NAME_BUF_SIZE 32
|
|
|
|
|
|
static void probe_hcall_entry(void *ignored, unsigned long opcode, unsigned long *args)
|
|
{
|
|
struct hcall_stats *h;
|
|
|
|
if (opcode > MAX_HCALL_OPCODE)
|
|
return;
|
|
|
|
h = this_cpu_ptr(&hcall_stats[opcode / 4]);
|
|
h->tb_start = mftb();
|
|
h->purr_start = mfspr(SPRN_PURR);
|
|
}
|
|
|
|
static void probe_hcall_exit(void *ignored, unsigned long opcode, unsigned long retval,
|
|
unsigned long *retbuf)
|
|
{
|
|
struct hcall_stats *h;
|
|
|
|
if (opcode > MAX_HCALL_OPCODE)
|
|
return;
|
|
|
|
h = this_cpu_ptr(&hcall_stats[opcode / 4]);
|
|
h->num_calls++;
|
|
h->tb_total += mftb() - h->tb_start;
|
|
h->purr_total += mfspr(SPRN_PURR) - h->purr_start;
|
|
}
|
|
|
|
static int __init hcall_inst_init(void)
|
|
{
|
|
struct dentry *hcall_root;
|
|
struct dentry *hcall_file;
|
|
char cpu_name_buf[CPU_NAME_BUF_SIZE];
|
|
int cpu;
|
|
|
|
if (!firmware_has_feature(FW_FEATURE_LPAR))
|
|
return 0;
|
|
|
|
if (register_trace_hcall_entry(probe_hcall_entry, NULL))
|
|
return -EINVAL;
|
|
|
|
if (register_trace_hcall_exit(probe_hcall_exit, NULL)) {
|
|
unregister_trace_hcall_entry(probe_hcall_entry, NULL);
|
|
return -EINVAL;
|
|
}
|
|
|
|
hcall_root = debugfs_create_dir(HCALL_ROOT_DIR, NULL);
|
|
if (!hcall_root)
|
|
return -ENOMEM;
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
snprintf(cpu_name_buf, CPU_NAME_BUF_SIZE, "cpu%d", cpu);
|
|
hcall_file = debugfs_create_file(cpu_name_buf, S_IRUGO,
|
|
hcall_root,
|
|
per_cpu(hcall_stats, cpu),
|
|
&hcall_inst_seq_fops);
|
|
if (!hcall_file)
|
|
return -ENOMEM;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
machine_device_initcall(pseries, hcall_inst_init);
|