Skip to content

Commit bd48c63

Browse files
committed
tools: Introduce tools/include/linux/time64.h for *SEC_PER_*SEC macros
And remove it from tools/perf/{perf,util}.h, making code that needs these macros to include linux/time64.h instead, to match how this is used in the kernel sources. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-e69fc1pvkgt57yvxqt6eunyg@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent ce90c12 commit bd48c63

12 files changed

Lines changed: 34 additions & 27 deletions

File tree

‎tools/include/linux/time64.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef _TOOLS_LINUX_TIME64_H
2+
#define _TOOLS_LINUX_TIME64_H
3+
4+
#define MSEC_PER_SEC 1000L
5+
#define USEC_PER_MSEC 1000L
6+
#define NSEC_PER_USEC 1000L
7+
#define NSEC_PER_MSEC 1000000L
8+
#define USEC_PER_SEC 1000000L
9+
#define NSEC_PER_SEC 1000000000L
10+
#define FSEC_PER_SEC 1000000000000000LL
11+
12+
#endif /* _LINUX_TIME64_H */

‎tools/perf/MANIFEST‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,5 @@ tools/include/linux/stringify.h
7777
tools/include/linux/types.h
7878
tools/include/linux/err.h
7979
tools/include/linux/bitmap.h
80+
tools/include/linux/time64.h
8081
tools/arch/*/include/uapi/asm/perf_regs.h

‎tools/perf/builtin-kvm.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <sys/timerfd.h>
2525
#endif
2626

27+
#include <linux/time64.h>
2728
#include <termios.h>
2829
#include <semaphore.h>
2930
#include <pthread.h>

‎tools/perf/builtin-script.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "util/thread-stack.h"
2525
#include <linux/bitmap.h>
2626
#include <linux/stringify.h>
27+
#include <linux/time64.h>
2728
#include "asm/bug.h"
2829
#include "util/mem-events.h"
2930

@@ -464,9 +465,9 @@ static void print_sample_start(struct perf_sample *sample,
464465

465466
if (PRINT_FIELD(TIME)) {
466467
nsecs = sample->time;
467-
secs = nsecs / NSECS_PER_SEC;
468-
nsecs -= secs * NSECS_PER_SEC;
469-
usecs = nsecs / NSECS_PER_USEC;
468+
secs = nsecs / NSEC_PER_SEC;
469+
nsecs -= secs * NSEC_PER_SEC;
470+
usecs = nsecs / NSEC_PER_USEC;
470471
if (nanosecs)
471472
printf("%5lu.%09llu: ", secs, nsecs);
472473
else

‎tools/perf/builtin-stat.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "util/group.h"
6666
#include "asm/bug.h"
6767

68+
#include <linux/time64.h>
6869
#include <api/fs/fs.h>
6970
#include <stdlib.h>
7071
#include <sys/prctl.h>
@@ -354,7 +355,7 @@ static void process_interval(void)
354355
diff_timespec(&rs, &ts, &ref_time);
355356

356357
if (STAT_RECORD) {
357-
if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSECS_PER_SEC + rs.tv_nsec, INTERVAL))
358+
if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSEC_PER_SEC + rs.tv_nsec, INTERVAL))
358359
pr_err("failed to write stat round event\n");
359360
}
360361

@@ -2175,8 +2176,8 @@ static int process_stat_round_event(struct perf_tool *tool __maybe_unused,
21752176
update_stats(&walltime_nsecs_stats, stat_round->time);
21762177

21772178
if (stat_config.interval && stat_round->time) {
2178-
tsh.tv_sec = stat_round->time / NSECS_PER_SEC;
2179-
tsh.tv_nsec = stat_round->time % NSECS_PER_SEC;
2179+
tsh.tv_sec = stat_round->time / NSEC_PER_SEC;
2180+
tsh.tv_nsec = stat_round->time % NSEC_PER_SEC;
21802181
ts = &tsh;
21812182
}
21822183

‎tools/perf/builtin-trace.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <linux/audit.h>
4646
#include <linux/random.h>
4747
#include <linux/stringify.h>
48+
#include <linux/time64.h>
4849

4950
#ifndef O_CLOEXEC
5051
# define O_CLOEXEC 02000000

‎tools/perf/perf.h‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
1414
#define HAVE_ATTR_TEST
1515
#include "perf-sys.h"
1616

17-
#ifndef NSEC_PER_SEC
18-
# define NSEC_PER_SEC 1000000000ULL
19-
#endif
20-
#ifndef NSEC_PER_USEC
21-
# define NSEC_PER_USEC 1000ULL
22-
#endif
23-
2417
static inline unsigned long long rdclock(void)
2518
{
2619
struct timespec ts;

‎tools/perf/util/debug.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdarg.h>
77
#include <stdio.h>
88
#include <api/debug.h>
9+
#include <linux/time64.h>
910

1011
#include "cache.h"
1112
#include "color.h"
@@ -14,9 +15,6 @@
1415
#include "util.h"
1516
#include "target.h"
1617

17-
#define NSECS_PER_SEC 1000000000ULL
18-
#define NSECS_PER_USEC 1000ULL
19-
2018
int verbose;
2119
bool dump_trace = false, quiet = false;
2220
int debug_ordered_events;
@@ -54,9 +52,9 @@ static int veprintf_time(u64 t, const char *fmt, va_list args)
5452
int ret = 0;
5553
u64 secs, usecs, nsecs = t;
5654

57-
secs = nsecs / NSECS_PER_SEC;
58-
nsecs -= secs * NSECS_PER_SEC;
59-
usecs = nsecs / NSECS_PER_USEC;
55+
secs = nsecs / NSEC_PER_SEC;
56+
nsecs -= secs * NSEC_PER_SEC;
57+
usecs = nsecs / NSEC_PER_USEC;
6058

6159
ret = fprintf(stderr, "[%13" PRIu64 ".%06" PRIu64 "] ",
6260
secs, usecs);

‎tools/perf/util/scripting-engines/trace-event-perl.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <ctype.h>
2626
#include <errno.h>
2727
#include <linux/bitmap.h>
28+
#include <linux/time64.h>
2829

2930
#include "../util.h"
3031
#include <EXTERN.h>
@@ -359,8 +360,8 @@ static void perl_process_tracepoint(struct perf_sample *sample,
359360
if (!test_and_set_bit(event->id, events_defined))
360361
define_event_symbols(event, handler, event->print_fmt.args);
361362

362-
s = nsecs / NSECS_PER_SEC;
363-
ns = nsecs - s * NSECS_PER_SEC;
363+
s = nsecs / NSEC_PER_SEC;
364+
ns = nsecs - s * NSEC_PER_SEC;
364365

365366
scripting_context->event_data = data;
366367
scripting_context->pevent = evsel->tp_format->pevent;

‎tools/perf/util/scripting-engines/trace-event-python.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <stdbool.h>
2828
#include <errno.h>
2929
#include <linux/bitmap.h>
30+
#include <linux/time64.h>
3031

3132
#include "../../perf.h"
3233
#include "../debug.h"
@@ -426,8 +427,8 @@ static void python_process_tracepoint(struct perf_sample *sample,
426427
if (!dict)
427428
Py_FatalError("couldn't create Python dict");
428429
}
429-
s = nsecs / NSECS_PER_SEC;
430-
ns = nsecs - s * NSECS_PER_SEC;
430+
s = nsecs / NSEC_PER_SEC;
431+
ns = nsecs - s * NSEC_PER_SEC;
431432

432433
scripting_context->event_data = data;
433434
scripting_context->pevent = evsel->tp_format->pevent;

0 commit comments

Comments
 (0)