Skip to content

Commit e4b8b3f

Browse files
Jan GlauberMartin Schwidefsky
authored andcommitted
s390: add support for runtime instrumentation
Allow user-space threads to use runtime instrumentation (RI). To enable RI for a thread there is a new s390 specific system call, sys_s390_runtime_instr, that takes as parameter a realtime signal number. If the RI facility is available the system call sets up a control block for the calling thread with the appropriate permissions for the thread to modify the control block. The user-space thread can then use the store and modify RI instructions to alter the control block and start/stop the instrumentation via RION/RIOFF. If the user specified program buffer runs full RI triggers an external interrupt. The external interrupt is translated to a real-time signal that is delivered to the thread that enabled RI on that CPU. The number of the real-time signal is the number specified in the RI system call. So, user-space can select any available real-time signal number in case the application itself uses real-time signals for other purposes. The kernel saves the RI control blocks on task switch only if the running thread was enabled for RI. Therefore, the performance impact on task switch should be negligible if RI is not used. RI is only enabled for user-space mode and is disabled for the supervisor state. Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Jan Glauber <jang@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 0d804b2 commit e4b8b3f

14 files changed

Lines changed: 300 additions & 3 deletions

File tree

‎arch/s390/include/asm/cpu_mf.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@
2121
#define CPU_MF_INT_SF_LSDA (1 << 22) /* loss of sample data alert */
2222
#define CPU_MF_INT_CF_CACA (1 << 7) /* counter auth. change alert */
2323
#define CPU_MF_INT_CF_LCDA (1 << 6) /* loss of counter data alert */
24+
#define CPU_MF_INT_RI_HALTED (1 << 5) /* run-time instr. halted */
25+
#define CPU_MF_INT_RI_BUF_FULL (1 << 4) /* run-time instr. program
26+
buffer full */
2427

2528
#define CPU_MF_INT_CF_MASK (CPU_MF_INT_CF_CACA|CPU_MF_INT_CF_LCDA)
2629
#define CPU_MF_INT_SF_MASK (CPU_MF_INT_SF_IAE|CPU_MF_INT_SF_ISE| \
2730
CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA| \
2831
CPU_MF_INT_SF_LSDA)
32+
#define CPU_MF_INT_RI_MASK (CPU_MF_INT_RI_HALTED|CPU_MF_INT_RI_BUF_FULL)
2933

3034
/* CPU measurement facility support */
3135
static inline int cpum_cf_avail(void)

‎arch/s390/include/asm/irq.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum interruption_class {
1919
EXTINT_IUC,
2020
EXTINT_CMS,
2121
EXTINT_CMC,
22+
EXTINT_CMR,
2223
IOINT_CIO,
2324
IOINT_QAI,
2425
IOINT_DAS,

‎arch/s390/include/asm/processor.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <asm/page.h>
1818
#include <asm/ptrace.h>
1919
#include <asm/setup.h>
20+
#include <asm/runtime_instr.h>
2021

2122
/*
2223
* Default implementation of macro that returns current
@@ -78,6 +79,9 @@ struct thread_struct {
7879
/* pfault_wait is used to block the process on a pfault event */
7980
unsigned long pfault_wait;
8081
struct list_head list;
82+
/* cpu runtime instrumentation */
83+
struct runtime_instr_cb *ri_cb;
84+
int ri_signum;
8185
};
8286

8387
typedef struct thread_struct thread_struct;

‎arch/s390/include/asm/ptrace.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ typedef struct
235235
#define PSW_MASK_ASC 0x0000C000UL
236236
#define PSW_MASK_CC 0x00003000UL
237237
#define PSW_MASK_PM 0x00000F00UL
238+
#define PSW_MASK_RI 0x00000000UL
238239
#define PSW_MASK_EA 0x00000000UL
239240
#define PSW_MASK_BA 0x00000000UL
240241

@@ -264,10 +265,11 @@ typedef struct
264265
#define PSW_MASK_ASC 0x0000C00000000000UL
265266
#define PSW_MASK_CC 0x0000300000000000UL
266267
#define PSW_MASK_PM 0x00000F0000000000UL
268+
#define PSW_MASK_RI 0x0000008000000000UL
267269
#define PSW_MASK_EA 0x0000000100000000UL
268270
#define PSW_MASK_BA 0x0000000080000000UL
269271

270-
#define PSW_MASK_USER 0x00003F0180000000UL
272+
#define PSW_MASK_USER 0x00003F8180000000UL
271273

272274
#define PSW_ADDR_AMODE 0x0000000000000000UL
273275
#define PSW_ADDR_INSN 0xFFFFFFFFFFFFFFFFUL
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#ifndef _RUNTIME_INSTR_H
2+
#define _RUNTIME_INSTR_H
3+
4+
#define S390_RUNTIME_INSTR_START 0x1
5+
#define S390_RUNTIME_INSTR_STOP 0x2
6+
7+
struct runtime_instr_cb {
8+
__u64 buf_current;
9+
__u64 buf_origin;
10+
__u64 buf_limit;
11+
12+
__u32 valid : 1;
13+
__u32 pstate : 1;
14+
__u32 pstate_set_buf : 1;
15+
__u32 home_space : 1;
16+
__u32 altered : 1;
17+
__u32 : 3;
18+
__u32 pstate_sample : 1;
19+
__u32 sstate_sample : 1;
20+
__u32 pstate_collect : 1;
21+
__u32 sstate_collect : 1;
22+
__u32 : 1;
23+
__u32 halted_int : 1;
24+
__u32 int_requested : 1;
25+
__u32 buffer_full_int : 1;
26+
__u32 key : 4;
27+
__u32 : 9;
28+
__u32 rgs : 3;
29+
30+
__u32 mode : 4;
31+
__u32 next : 1;
32+
__u32 mae : 1;
33+
__u32 : 2;
34+
__u32 call_type_br : 1;
35+
__u32 return_type_br : 1;
36+
__u32 other_type_br : 1;
37+
__u32 bc_other_type : 1;
38+
__u32 emit : 1;
39+
__u32 tx_abort : 1;
40+
__u32 : 2;
41+
__u32 bp_xn : 1;
42+
__u32 bp_xt : 1;
43+
__u32 bp_ti : 1;
44+
__u32 bp_ni : 1;
45+
__u32 suppr_y : 1;
46+
__u32 suppr_z : 1;
47+
48+
__u32 dc_miss_extra : 1;
49+
__u32 lat_lev_ignore : 1;
50+
__u32 ic_lat_lev : 4;
51+
__u32 dc_lat_lev : 4;
52+
53+
__u64 reserved1;
54+
__u64 scaling_factor;
55+
__u64 rsic;
56+
__u64 reserved2;
57+
} __packed __aligned(8);
58+
59+
extern struct runtime_instr_cb runtime_instr_empty_cb;
60+
61+
static inline void load_runtime_instr_cb(struct runtime_instr_cb *cb)
62+
{
63+
asm volatile(".insn rsy,0xeb0000000060,0,0,%0" /* LRIC */
64+
: : "Q" (*cb));
65+
}
66+
67+
static inline void store_runtime_instr_cb(struct runtime_instr_cb *cb)
68+
{
69+
asm volatile(".insn rsy,0xeb0000000061,0,0,%0" /* STRIC */
70+
: "=Q" (*cb) : : "cc");
71+
}
72+
73+
static inline void save_ri_cb(struct runtime_instr_cb *cb_prev)
74+
{
75+
#ifdef CONFIG_64BIT
76+
if (cb_prev)
77+
store_runtime_instr_cb(cb_prev);
78+
#endif
79+
}
80+
81+
static inline void restore_ri_cb(struct runtime_instr_cb *cb_next,
82+
struct runtime_instr_cb *cb_prev)
83+
{
84+
#ifdef CONFIG_64BIT
85+
if (cb_next)
86+
load_runtime_instr_cb(cb_next);
87+
else if (cb_prev)
88+
load_runtime_instr_cb(&runtime_instr_empty_cb);
89+
#endif
90+
}
91+
92+
#ifdef CONFIG_64BIT
93+
extern void exit_thread_runtime_instr(void);
94+
#else
95+
static inline void exit_thread_runtime_instr(void) { }
96+
#endif
97+
98+
#endif /* _RUNTIME_INSTR_H */

‎arch/s390/include/asm/switch_to.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ static inline void restore_access_regs(unsigned int *acrs)
8080
if (prev->mm) { \
8181
save_fp_regs(&prev->thread.fp_regs); \
8282
save_access_regs(&prev->thread.acrs[0]); \
83+
save_ri_cb(prev->thread.ri_cb); \
8384
} \
8485
if (next->mm) { \
8586
restore_fp_regs(&next->thread.fp_regs); \
8687
restore_access_regs(&next->thread.acrs[0]); \
88+
restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb); \
8789
update_per_regs(next); \
8890
} \
8991
prev = __switch_to(prev,next); \

‎arch/s390/include/asm/unistd.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@
277277
#define __NR_setns 339
278278
#define __NR_process_vm_readv 340
279279
#define __NR_process_vm_writev 341
280-
#define NR_syscalls 342
280+
#define __NR_s390_runtime_instr 342
281+
#define NR_syscalls 343
281282

282283
/*
283284
* There are some system calls that are not present on 64 bit, some

‎arch/s390/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
4949
obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o
5050
obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
5151
obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_cpum_cf.o
52-
obj-$(CONFIG_64BIT) += cache.o
52+
obj-$(CONFIG_64BIT) += runtime_instr.o cache.o
5353

5454
# Kexec part
5555
S390_KEXEC_OBJS := machine_kexec.o

‎arch/s390/kernel/compat_wrapper.S‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,3 +1646,8 @@ ENTRY(compat_sys_process_vm_writev_wrapper)
16461646
llgf %r0,164(%r15) # unsigned long
16471647
stg %r0,160(%r15)
16481648
jg compat_sys_process_vm_writev
1649+
1650+
ENTRY(sys_s390_runtime_instr_wrapper)
1651+
lgfr %r2,%r2 # int
1652+
lgfr %r3,%r3 # int
1653+
jg sys_s390_runtime_instr

‎arch/s390/kernel/dis.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ enum {
315315
LONG_INSN_POPCNT,
316316
LONG_INSN_RISBHG,
317317
LONG_INSN_RISBLG,
318+
LONG_INSN_RINEXT,
319+
LONG_INSN_RIEMIT,
318320
};
319321

320322
static char *long_insn_name[] = {
@@ -330,6 +332,8 @@ static char *long_insn_name[] = {
330332
[LONG_INSN_POPCNT] = "popcnt",
331333
[LONG_INSN_RISBHG] = "risbhg",
332334
[LONG_INSN_RISBLG] = "risblk",
335+
[LONG_INSN_RINEXT] = "rinext",
336+
[LONG_INSN_RIEMIT] = "riemit",
333337
};
334338

335339
static struct insn opcode[] = {
@@ -582,6 +586,17 @@ static struct insn opcode_a7[] = {
582586
{ "", 0, INSTR_INVALID }
583587
};
584588

589+
static struct insn opcode_aa[] = {
590+
#ifdef CONFIG_64BIT
591+
{ { 0, LONG_INSN_RINEXT }, 0x00, INSTR_RI_RI },
592+
{ "rion", 0x01, INSTR_RI_RI },
593+
{ "tric", 0x02, INSTR_RI_RI },
594+
{ "rioff", 0x03, INSTR_RI_RI },
595+
{ { 0, LONG_INSN_RIEMIT }, 0x04, INSTR_RI_RI },
596+
#endif
597+
{ "", 0, INSTR_INVALID }
598+
};
599+
585600
static struct insn opcode_b2[] = {
586601
#ifdef CONFIG_64BIT
587602
{ "sske", 0x2b, INSTR_RRF_M0RR },
@@ -1210,6 +1225,9 @@ static struct insn opcode_eb[] = {
12101225
{ "cliy", 0x55, INSTR_SIY_URD },
12111226
{ "oiy", 0x56, INSTR_SIY_URD },
12121227
{ "xiy", 0x57, INSTR_SIY_URD },
1228+
{ "lric", 0x60, INSTR_RSY_RDRM },
1229+
{ "stric", 0x61, INSTR_RSY_RDRM },
1230+
{ "mric", 0x62, INSTR_RSY_RDRM },
12131231
{ "icmh", 0x80, INSTR_RSE_RURD },
12141232
{ "icmh", 0x80, INSTR_RSY_RURD },
12151233
{ "icmy", 0x81, INSTR_RSY_RURD },
@@ -1408,6 +1426,9 @@ static struct insn *find_insn(unsigned char *code)
14081426
case 0xa7:
14091427
table = opcode_a7;
14101428
break;
1429+
case 0xaa:
1430+
table = opcode_aa;
1431+
break;
14111432
case 0xb2:
14121433
table = opcode_b2;
14131434
break;

0 commit comments

Comments
 (0)