xref: /openbmc/linux/tools/perf/trace/beauty/futex_op.c (revision 5ef12cb4)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/futex.h>
3 
4 #ifndef FUTEX_WAIT_BITSET
5 #define FUTEX_WAIT_BITSET	  9
6 #endif
7 #ifndef FUTEX_WAKE_BITSET
8 #define FUTEX_WAKE_BITSET	 10
9 #endif
10 #ifndef FUTEX_WAIT_REQUEUE_PI
11 #define FUTEX_WAIT_REQUEUE_PI	 11
12 #endif
13 #ifndef FUTEX_CMP_REQUEUE_PI
14 #define FUTEX_CMP_REQUEUE_PI	 12
15 #endif
16 #ifndef FUTEX_CLOCK_REALTIME
17 #define FUTEX_CLOCK_REALTIME	256
18 #endif
19 
20 static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct syscall_arg *arg)
21 {
22 	enum syscall_futex_args {
23 		SCF_UADDR   = (1 << 0),
24 		SCF_OP	    = (1 << 1),
25 		SCF_VAL	    = (1 << 2),
26 		SCF_TIMEOUT = (1 << 3),
27 		SCF_UADDR2  = (1 << 4),
28 		SCF_VAL3    = (1 << 5),
29 	};
30 	int op = arg->val;
31 	int cmd = op & FUTEX_CMD_MASK;
32 	size_t printed = 0;
33 
34 	switch (cmd) {
35 #define	P_FUTEX_OP(n) case FUTEX_##n: printed = scnprintf(bf, size, #n);
36 	P_FUTEX_OP(WAIT);	    arg->mask |= SCF_VAL3|SCF_UADDR2;		  break;
37 	P_FUTEX_OP(WAKE);	    arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break;
38 	P_FUTEX_OP(FD);		    arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break;
39 	P_FUTEX_OP(REQUEUE);	    arg->mask |= SCF_VAL3|SCF_TIMEOUT;	          break;
40 	P_FUTEX_OP(CMP_REQUEUE);    arg->mask |= SCF_TIMEOUT;			  break;
41 	P_FUTEX_OP(CMP_REQUEUE_PI); arg->mask |= SCF_TIMEOUT;			  break;
42 	P_FUTEX_OP(WAKE_OP);							  break;
43 	P_FUTEX_OP(LOCK_PI);	    arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break;
44 	P_FUTEX_OP(UNLOCK_PI);	    arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break;
45 	P_FUTEX_OP(TRYLOCK_PI);	    arg->mask |= SCF_VAL3|SCF_UADDR2;		  break;
46 	P_FUTEX_OP(WAIT_BITSET);    arg->mask |= SCF_UADDR2;			  break;
47 	P_FUTEX_OP(WAKE_BITSET);    arg->mask |= SCF_UADDR2;			  break;
48 	P_FUTEX_OP(WAIT_REQUEUE_PI);						  break;
49 	default: printed = scnprintf(bf, size, "%#x", cmd);			  break;
50 	}
51 
52 	if (op & FUTEX_PRIVATE_FLAG)
53 		printed += scnprintf(bf + printed, size - printed, "|PRIV");
54 
55 	if (op & FUTEX_CLOCK_REALTIME)
56 		printed += scnprintf(bf + printed, size - printed, "|CLKRT");
57 
58 	return printed;
59 }
60 
61 #define SCA_FUTEX_OP  syscall_arg__scnprintf_futex_op
62