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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent ce90c12d
#ifndef _TOOLS_LINUX_TIME64_H
#define _TOOLS_LINUX_TIME64_H
#define MSEC_PER_SEC 1000L
#define USEC_PER_MSEC 1000L
#define NSEC_PER_USEC 1000L
#define NSEC_PER_MSEC 1000000L
#define USEC_PER_SEC 1000000L
#define NSEC_PER_SEC 1000000000L
#define FSEC_PER_SEC 1000000000000000LL
#endif /* _LINUX_TIME64_H */
...@@ -77,4 +77,5 @@ tools/include/linux/stringify.h ...@@ -77,4 +77,5 @@ tools/include/linux/stringify.h
tools/include/linux/types.h tools/include/linux/types.h
tools/include/linux/err.h tools/include/linux/err.h
tools/include/linux/bitmap.h tools/include/linux/bitmap.h
tools/include/linux/time64.h
tools/arch/*/include/uapi/asm/perf_regs.h tools/arch/*/include/uapi/asm/perf_regs.h
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <sys/timerfd.h> #include <sys/timerfd.h>
#endif #endif
#include <linux/time64.h>
#include <termios.h> #include <termios.h>
#include <semaphore.h> #include <semaphore.h>
#include <pthread.h> #include <pthread.h>
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "util/thread-stack.h" #include "util/thread-stack.h"
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include <linux/stringify.h> #include <linux/stringify.h>
#include <linux/time64.h>
#include "asm/bug.h" #include "asm/bug.h"
#include "util/mem-events.h" #include "util/mem-events.h"
...@@ -464,9 +465,9 @@ static void print_sample_start(struct perf_sample *sample, ...@@ -464,9 +465,9 @@ static void print_sample_start(struct perf_sample *sample,
if (PRINT_FIELD(TIME)) { if (PRINT_FIELD(TIME)) {
nsecs = sample->time; nsecs = sample->time;
secs = nsecs / NSECS_PER_SEC; secs = nsecs / NSEC_PER_SEC;
nsecs -= secs * NSECS_PER_SEC; nsecs -= secs * NSEC_PER_SEC;
usecs = nsecs / NSECS_PER_USEC; usecs = nsecs / NSEC_PER_USEC;
if (nanosecs) if (nanosecs)
printf("%5lu.%09llu: ", secs, nsecs); printf("%5lu.%09llu: ", secs, nsecs);
else else
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
#include "util/group.h" #include "util/group.h"
#include "asm/bug.h" #include "asm/bug.h"
#include <linux/time64.h>
#include <api/fs/fs.h> #include <api/fs/fs.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/prctl.h> #include <sys/prctl.h>
...@@ -354,7 +355,7 @@ static void process_interval(void) ...@@ -354,7 +355,7 @@ static void process_interval(void)
diff_timespec(&rs, &ts, &ref_time); diff_timespec(&rs, &ts, &ref_time);
if (STAT_RECORD) { if (STAT_RECORD) {
if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSECS_PER_SEC + rs.tv_nsec, INTERVAL)) if (WRITE_STAT_ROUND_EVENT(rs.tv_sec * NSEC_PER_SEC + rs.tv_nsec, INTERVAL))
pr_err("failed to write stat round event\n"); pr_err("failed to write stat round event\n");
} }
...@@ -2175,8 +2176,8 @@ static int process_stat_round_event(struct perf_tool *tool __maybe_unused, ...@@ -2175,8 +2176,8 @@ static int process_stat_round_event(struct perf_tool *tool __maybe_unused,
update_stats(&walltime_nsecs_stats, stat_round->time); update_stats(&walltime_nsecs_stats, stat_round->time);
if (stat_config.interval && stat_round->time) { if (stat_config.interval && stat_round->time) {
tsh.tv_sec = stat_round->time / NSECS_PER_SEC; tsh.tv_sec = stat_round->time / NSEC_PER_SEC;
tsh.tv_nsec = stat_round->time % NSECS_PER_SEC; tsh.tv_nsec = stat_round->time % NSEC_PER_SEC;
ts = &tsh; ts = &tsh;
} }
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <linux/audit.h> #include <linux/audit.h>
#include <linux/random.h> #include <linux/random.h>
#include <linux/stringify.h> #include <linux/stringify.h>
#include <linux/time64.h>
#ifndef O_CLOEXEC #ifndef O_CLOEXEC
# define O_CLOEXEC 02000000 # define O_CLOEXEC 02000000
......
...@@ -14,13 +14,6 @@ void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, ...@@ -14,13 +14,6 @@ void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
#define HAVE_ATTR_TEST #define HAVE_ATTR_TEST
#include "perf-sys.h" #include "perf-sys.h"
#ifndef NSEC_PER_SEC
# define NSEC_PER_SEC 1000000000ULL
#endif
#ifndef NSEC_PER_USEC
# define NSEC_PER_USEC 1000ULL
#endif
static inline unsigned long long rdclock(void) static inline unsigned long long rdclock(void)
{ {
struct timespec ts; struct timespec ts;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <api/debug.h> #include <api/debug.h>
#include <linux/time64.h>
#include "cache.h" #include "cache.h"
#include "color.h" #include "color.h"
...@@ -14,9 +15,6 @@ ...@@ -14,9 +15,6 @@
#include "util.h" #include "util.h"
#include "target.h" #include "target.h"
#define NSECS_PER_SEC 1000000000ULL
#define NSECS_PER_USEC 1000ULL
int verbose; int verbose;
bool dump_trace = false, quiet = false; bool dump_trace = false, quiet = false;
int debug_ordered_events; int debug_ordered_events;
...@@ -54,9 +52,9 @@ static int veprintf_time(u64 t, const char *fmt, va_list args) ...@@ -54,9 +52,9 @@ static int veprintf_time(u64 t, const char *fmt, va_list args)
int ret = 0; int ret = 0;
u64 secs, usecs, nsecs = t; u64 secs, usecs, nsecs = t;
secs = nsecs / NSECS_PER_SEC; secs = nsecs / NSEC_PER_SEC;
nsecs -= secs * NSECS_PER_SEC; nsecs -= secs * NSEC_PER_SEC;
usecs = nsecs / NSECS_PER_USEC; usecs = nsecs / NSEC_PER_USEC;
ret = fprintf(stderr, "[%13" PRIu64 ".%06" PRIu64 "] ", ret = fprintf(stderr, "[%13" PRIu64 ".%06" PRIu64 "] ",
secs, usecs); secs, usecs);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include <linux/time64.h>
#include "../util.h" #include "../util.h"
#include <EXTERN.h> #include <EXTERN.h>
...@@ -359,8 +360,8 @@ static void perl_process_tracepoint(struct perf_sample *sample, ...@@ -359,8 +360,8 @@ static void perl_process_tracepoint(struct perf_sample *sample,
if (!test_and_set_bit(event->id, events_defined)) if (!test_and_set_bit(event->id, events_defined))
define_event_symbols(event, handler, event->print_fmt.args); define_event_symbols(event, handler, event->print_fmt.args);
s = nsecs / NSECS_PER_SEC; s = nsecs / NSEC_PER_SEC;
ns = nsecs - s * NSECS_PER_SEC; ns = nsecs - s * NSEC_PER_SEC;
scripting_context->event_data = data; scripting_context->event_data = data;
scripting_context->pevent = evsel->tp_format->pevent; scripting_context->pevent = evsel->tp_format->pevent;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <errno.h> #include <errno.h>
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include <linux/time64.h>
#include "../../perf.h" #include "../../perf.h"
#include "../debug.h" #include "../debug.h"
...@@ -426,8 +427,8 @@ static void python_process_tracepoint(struct perf_sample *sample, ...@@ -426,8 +427,8 @@ static void python_process_tracepoint(struct perf_sample *sample,
if (!dict) if (!dict)
Py_FatalError("couldn't create Python dict"); Py_FatalError("couldn't create Python dict");
} }
s = nsecs / NSECS_PER_SEC; s = nsecs / NSEC_PER_SEC;
ns = nsecs - s * NSECS_PER_SEC; ns = nsecs - s * NSEC_PER_SEC;
scripting_context->event_data = data; scripting_context->event_data = data;
scripting_context->pevent = evsel->tp_format->pevent; scripting_context->pevent = evsel->tp_format->pevent;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <byteswap.h> #include <byteswap.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/log2.h> #include <linux/log2.h>
#include <linux/time64.h>
#include <unistd.h> #include <unistd.h>
#include "callchain.h" #include "callchain.h"
#include "strlist.h" #include "strlist.h"
......
...@@ -179,10 +179,6 @@ static inline void *zalloc(size_t size) ...@@ -179,10 +179,6 @@ static inline void *zalloc(size_t size)
#undef tolower #undef tolower
#undef toupper #undef toupper
#ifndef NSEC_PER_MSEC
#define NSEC_PER_MSEC 1000000L
#endif
int parse_nsec_time(const char *str, u64 *ptime); int parse_nsec_time(const char *str, u64 *ptime);
extern unsigned char sane_ctype[256]; extern unsigned char sane_ctype[256];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment