mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org
Subject: [PATCH] perf: Fix time formatting for Y2038-compliant 32-bit architectures
Date: Thu, 01 Oct 2015 01:44:51 +0100	[thread overview]
Message-ID: <1443660291.2730.17.camel@decadent.org.uk> (raw)

[-- Attachment #1: Type: text/plain, Size: 3767 bytes --]

Fixes compiler errors such as this on x32:

builtin-stat.c: In function ‘print_interval’:
builtin-stat.c:909:18: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘__time_t {aka long long int}’ [-Werror=format=]
  sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep);
                  ^

This isn't sufficient to make perf build for x32, but it gets us
closer and helps to prepare for Y2038 support on other 32-bit
architectures.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 tools/perf/bench/sched-messaging.c | 6 +++---
 tools/perf/bench/sched-pipe.c      | 8 ++++----
 tools/perf/builtin-kvm.c           | 2 +-
 tools/perf/builtin-stat.c          | 4 +++-
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c
index d7f281c..f71c41d 100644
--- a/tools/perf/bench/sched-messaging.c
+++ b/tools/perf/bench/sched-messaging.c
@@ -310,12 +310,12 @@ int bench_sched_messaging(int argc, const char **argv,
 		printf("# %d groups == %d %s run\n\n",
 		       num_groups, num_groups * 2 * num_fds,
 		       thread_mode ? "threads" : "processes");
-		printf(" %14s: %lu.%03lu [sec]\n", "Total time",
-		       diff.tv_sec,
+		printf(" %14s: %llu.%03lu [sec]\n", "Total time",
+		       (unsigned long long) diff.tv_sec,
 		       (unsigned long) (diff.tv_usec/1000));
 		break;
 	case BENCH_FORMAT_SIMPLE:
-		printf("%lu.%03lu\n", diff.tv_sec,
+		printf("%llu.%03lu\n", (unsigned long long) diff.tv_sec,
 		       (unsigned long) (diff.tv_usec/1000));
 		break;
 	default:
diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index 005cc28..69ce697 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -156,8 +156,8 @@ int bench_sched_pipe(int argc, const char **argv, const char *prefix __maybe_unu
 		result_usec = diff.tv_sec * 1000000;
 		result_usec += diff.tv_usec;
 
-		printf(" %14s: %lu.%03lu [sec]\n\n", "Total time",
-		       diff.tv_sec,
+		printf(" %14s: %llu.%03lu [sec]\n\n", "Total time",
+		       (unsigned long long) diff.tv_sec,
 		       (unsigned long) (diff.tv_usec/1000));
 
 		printf(" %14lf usecs/op\n",
@@ -168,8 +168,8 @@ int bench_sched_pipe(int argc, const char **argv, const char *prefix __maybe_unu
 		break;
 
 	case BENCH_FORMAT_SIMPLE:
-		printf("%lu.%03lu\n",
-		       diff.tv_sec,
+		printf("%llu.%03lu\n",
+		       (unsigned long long) diff.tv_sec,
 		       (unsigned long) (diff.tv_usec / 1000));
 		break;
 
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index fc1cffb..26dff61 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -566,7 +566,7 @@ static void show_timeofday(void)
 	gettimeofday(&tv, NULL);
 	if (localtime_r(&tv.tv_sec, &ltime)) {
 		strftime(date, sizeof(date), "%H:%M:%S", &ltime);
-		pr_info("%s.%06ld", date, tv.tv_usec);
+		pr_info("%s.%06lu", date, (unsigned long) tv.tv_usec);
 	} else
 		pr_info("00:00:00.000000");
 
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index d46dbb1..fca784f 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -780,7 +780,9 @@ static void print_interval(char *prefix, struct timespec *ts)
 	FILE *output = stat_config.output;
 	static int num_print_interval;
 
-	sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep);
+	sprintf(prefix, "%6llu.%09lu%s",
+		(unsigned long long) ts->tv_sec, (unsigned long) ts->tv_nsec,
+		csv_sep);
 
 	if (num_print_interval == 0 && !csv_output) {
 		switch (stat_config.aggr_mode) {
-- 
Ben Hutchings
Knowledge is power.  France is bacon.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]

                 reply	other threads:[~2015-10-01  0:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443660291.2730.17.camel@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=y2038@lists.linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®