@@ -38,10 +38,10 @@ unsigned long long timing(clockid_t clk_id, unsigned long long samples)
38
38
i *= 1000000000ULL ;
39
39
i += finish .tv_nsec - start .tv_nsec ;
40
40
41
- printf ("%lu.%09lu - %lu.%09lu = %llu (%.1fs)\n" ,
42
- finish .tv_sec , finish .tv_nsec ,
43
- start .tv_sec , start .tv_nsec ,
44
- i , (double )i / 1000000000.0 );
41
+ ksft_print_msg ("%lu.%09lu - %lu.%09lu = %llu (%.1fs)\n" ,
42
+ finish .tv_sec , finish .tv_nsec ,
43
+ start .tv_sec , start .tv_nsec ,
44
+ i , (double )i / 1000000000.0 );
45
45
46
46
return i ;
47
47
}
@@ -53,7 +53,7 @@ unsigned long long calibrate(void)
53
53
pid_t pid , ret ;
54
54
int seconds = 15 ;
55
55
56
- printf ("Calibrating sample size for %d seconds worth of syscalls ...\n" , seconds );
56
+ ksft_print_msg ("Calibrating sample size for %d seconds worth of syscalls ...\n" , seconds );
57
57
58
58
samples = 0 ;
59
59
pid = getpid ();
@@ -102,14 +102,14 @@ long compare(const char *name_one, const char *name_eval, const char *name_two,
102
102
{
103
103
bool good ;
104
104
105
- printf ("\t%s %s %s (%lld %s %lld): " , name_one , name_eval , name_two ,
106
- (long long )one , name_eval , (long long )two );
105
+ ksft_print_msg ("\t%s %s %s (%lld %s %lld): " , name_one , name_eval , name_two ,
106
+ (long long )one , name_eval , (long long )two );
107
107
if (one > INT_MAX ) {
108
- printf ("Miscalculation! Measurement went negative: %lld\n" , (long long )one );
108
+ ksft_print_msg ("Miscalculation! Measurement went negative: %lld\n" , (long long )one );
109
109
return 1 ;
110
110
}
111
111
if (two > INT_MAX ) {
112
- printf ("Miscalculation! Measurement went negative: %lld\n" , (long long )two );
112
+ ksft_print_msg ("Miscalculation! Measurement went negative: %lld\n" , (long long )two );
113
113
return 1 ;
114
114
}
115
115
@@ -145,24 +145,27 @@ int main(int argc, char *argv[])
145
145
146
146
setbuf (stdout , NULL );
147
147
148
- printf ("Running on:\n" );
148
+ ksft_print_msg ("Running on:\n" );
149
+ ksft_print_msg ("" );
149
150
system ("uname -a" );
150
151
151
- printf ("Current BPF sysctl settings:\n" );
152
+ ksft_print_msg ("Current BPF sysctl settings:\n" );
152
153
/* Avoid using "sysctl" which may not be installed. */
154
+ ksft_print_msg ("" );
153
155
system ("grep -H . /proc/sys/net/core/bpf_jit_enable" );
156
+ ksft_print_msg ("" );
154
157
system ("grep -H . /proc/sys/net/core/bpf_jit_harden" );
155
158
156
159
if (argc > 1 )
157
160
samples = strtoull (argv [1 ], NULL , 0 );
158
161
else
159
162
samples = calibrate ();
160
163
161
- printf ("Benchmarking %llu syscalls...\n" , samples );
164
+ ksft_print_msg ("Benchmarking %llu syscalls...\n" , samples );
162
165
163
166
/* Native call */
164
167
native = timing (CLOCK_PROCESS_CPUTIME_ID , samples ) / samples ;
165
- printf ("getpid native: %llu ns\n" , native );
168
+ ksft_print_msg ("getpid native: %llu ns\n" , native );
166
169
167
170
ret = prctl (PR_SET_NO_NEW_PRIVS , 1 , 0 , 0 , 0 );
168
171
assert (ret == 0 );
@@ -172,33 +175,33 @@ int main(int argc, char *argv[])
172
175
assert (ret == 0 );
173
176
174
177
bitmap1 = timing (CLOCK_PROCESS_CPUTIME_ID , samples ) / samples ;
175
- printf ("getpid RET_ALLOW 1 filter (bitmap): %llu ns\n" , bitmap1 );
178
+ ksft_print_msg ("getpid RET_ALLOW 1 filter (bitmap): %llu ns\n" , bitmap1 );
176
179
177
180
/* Second filter resulting in a bitmap */
178
181
ret = prctl (PR_SET_SECCOMP , SECCOMP_MODE_FILTER , & bitmap_prog );
179
182
assert (ret == 0 );
180
183
181
184
bitmap2 = timing (CLOCK_PROCESS_CPUTIME_ID , samples ) / samples ;
182
- printf ("getpid RET_ALLOW 2 filters (bitmap): %llu ns\n" , bitmap2 );
185
+ ksft_print_msg ("getpid RET_ALLOW 2 filters (bitmap): %llu ns\n" , bitmap2 );
183
186
184
187
/* Third filter, can no longer be converted to bitmap */
185
188
ret = prctl (PR_SET_SECCOMP , SECCOMP_MODE_FILTER , & prog );
186
189
assert (ret == 0 );
187
190
188
191
filter1 = timing (CLOCK_PROCESS_CPUTIME_ID , samples ) / samples ;
189
- printf ("getpid RET_ALLOW 3 filters (full): %llu ns\n" , filter1 );
192
+ ksft_print_msg ("getpid RET_ALLOW 3 filters (full): %llu ns\n" , filter1 );
190
193
191
194
/* Fourth filter, can not be converted to bitmap because of filter 3 */
192
195
ret = prctl (PR_SET_SECCOMP , SECCOMP_MODE_FILTER , & bitmap_prog );
193
196
assert (ret == 0 );
194
197
195
198
filter2 = timing (CLOCK_PROCESS_CPUTIME_ID , samples ) / samples ;
196
- printf ("getpid RET_ALLOW 4 filters (full): %llu ns\n" , filter2 );
199
+ ksft_print_msg ("getpid RET_ALLOW 4 filters (full): %llu ns\n" , filter2 );
197
200
198
201
/* Estimations */
199
202
#define ESTIMATE (fmt , var , what ) do { \
200
203
var = (what); \
201
- printf ("Estimated " fmt ": %llu ns\n", var); \
204
+ ksft_print_msg ("Estimated " fmt ": %llu ns\n", var); \
202
205
if (var > INT_MAX) \
203
206
goto more_samples; \
204
207
} while (0)
@@ -218,7 +221,7 @@ int main(int argc, char *argv[])
218
221
ESTIMATE ("seccomp per-filter overhead (filters / 4)" , per_filter2 ,
219
222
(filter2 - native - entry ) / 4 );
220
223
221
- printf ("Expectations:\n" );
224
+ ksft_print_msg ("Expectations:\n" );
222
225
ret |= compare ("native" , "≤" , "1 bitmap" , native , le , bitmap1 );
223
226
bits = compare ("native" , "≤" , "1 filter" , native , le , filter1 );
224
227
if (bits )
@@ -230,7 +233,7 @@ int main(int argc, char *argv[])
230
233
bits = compare ("1 bitmapped" , "≈" , "2 bitmapped" ,
231
234
bitmap1 - native , approx , bitmap2 - native );
232
235
if (bits ) {
233
- printf ("Skipping constant action bitmap expectations: they appear unsupported.\n" );
236
+ ksft_print_msg ("Skipping constant action bitmap expectations: they appear unsupported.\n" );
234
237
goto out ;
235
238
}
236
239
@@ -242,7 +245,7 @@ int main(int argc, char *argv[])
242
245
goto out ;
243
246
244
247
more_samples :
245
- printf ("Saw unexpected benchmark result. Try running again with more samples?\n" );
248
+ ksft_print_msg ("Saw unexpected benchmark result. Try running again with more samples?\n" );
246
249
out :
247
250
return 0 ;
248
251
}
0 commit comments