From: Arun Sharma <asharma@fb.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: <linux-kernel@vger.kernel.org>, Kumar Sundararajan <kumar@fb.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
john stultz <johnstul@us.ibm.com>, Andy Lutomirski <luto@MIT.EDU>
Subject: Re: [PATCH 2/2] Add a thread cpu time implementation to vDSO
Date: Mon, 12 Dec 2011 13:19:37 -0800 [thread overview]
Message-ID: <4EE66FE9.1050202@fb.com> (raw)
In-Reply-To: <1323720791.2583.23.camel@edumazet-laptop>
On 12/12/11 12:13 PM, Eric Dumazet wrote:
>> +
>> +struct vcpu_data {
>> + struct vpercpu_data vpercpu[NR_CPUS];
>> + unsigned int tsc_khz;
>> + unsigned int tsc_unstable;
>> +};
>
> Thats a showstopper.
>
> Try to compile the thing with NR_CPUS=4096 ?
>
I get a link time error:
ld: section .data..percpu [0000000001ac2000 -> 0000000001ad48ff]
overlaps section .vvar [0000000001ac0000 -> 0000000001b0083f]
which I consider better than runtime memory corruption :)
I could add a BUILD_BUG_ON() that tries to catch this earlier in the
compile process.
Re: Fixing the build for NR_CPUS > 64
How about something along the lines of the following:
From: Arun Sharma <asharma@fb.com>
Date: Mon, 12 Dec 2011 13:13:43 -0800
Subject: [PATCH] Handle NR_CPUS > 64
---
arch/x86/kernel/tsc.c | 8 ++++++--
arch/x86/vdso/vclock_gettime.c | 4 ++--
include/linux/jiffies.h | 8 ++++++--
kernel/sched.c | 2 ++
4 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 1dc7205..45f3438 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -571,7 +571,11 @@ int recalibrate_cpu_khz(void)
cpufreq_scale(cpu_data(0).loops_per_jiffy,
cpu_khz_old, cpu_khz);
vcpu_data.tsc_khz = tsc_khz;
- vcpu_data.tsc_unstable = 0;
+#if CONFIG_NR_CPUS <= 64
+ vcpu_data.thread_cputime_disabled = 0;
+#else
+ vcpu_data.thread_cputime_disabled = 1;
+#endif
return 0;
} else
return -ENODEV;
@@ -790,7 +794,7 @@ void mark_tsc_unstable(char *reason)
tsc_unstable = 1;
sched_clock_stable = 0;
disable_sched_clock_irqtime();
- vcpu_data.tsc_unstable = 1;
+ vcpu_data.thread_cputime_disabled = 1;
jump_label_dec(&vcpu_data_enabled);
printk(KERN_INFO "Marking TSC unstable due to %s\n", reason);
/* Change only the rating, when not registered */
diff --git a/arch/x86/vdso/vclock_gettime.c b/arch/x86/vdso/vclock_gettime.c
index 61ab74b..e41a7e9 100644
--- a/arch/x86/vdso/vclock_gettime.c
+++ b/arch/x86/vdso/vclock_gettime.c
@@ -185,7 +185,7 @@ notrace static inline unsigned long
__do_thread_cpu_time(void)
const struct vcpu_data *vp = &VVAR(vcpu_data);
int cpu;
- if (vp->tsc_unstable) {
+ if (vp->thread_cputime_disabled) {
struct timespec ts;
vdso_fallback_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
return timespec_to_ns(&ts);
@@ -236,7 +236,7 @@ notrace int __vdso_clock_gettime(clockid_t clock,
struct timespec *ts)
case CLOCK_MONOTONIC_COARSE:
return do_monotonic_coarse(ts);
case CLOCK_THREAD_CPUTIME_ID:
- if (vp->tsc_unstable)
+ if (vp->thread_cputime_disabled)
break;
ns = do_thread_cpu_time();
if (likely(ns > 0)) {
diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index a0fe1f5..aec389f 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -319,9 +319,13 @@ struct vpercpu_data {
} ____cacheline_aligned;
struct vcpu_data {
- struct vpercpu_data vpercpu[NR_CPUS];
unsigned int tsc_khz;
- unsigned int tsc_unstable;
+ unsigned int thread_cputime_disabled;
+#if CONFIG_NR_CPUS <= 64
+ struct vpercpu_data vpercpu[NR_CPUS];
+#else
+ struct vpercpu_data vpercpu[1];
+#endif
};
extern struct vcpu_data vcpu_data;
diff --git a/kernel/sched.c b/kernel/sched.c
index a72545a..e4f38ae 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3216,11 +3216,13 @@ static void finish_task_switch(struct rq *rq,
struct task_struct *prev)
put_task_struct(prev);
}
+#if CONFIG_NR_CPUS <= 64
if (static_branch(&vcpu_data_enabled)) {
int cpu = smp_processor_id();
vcpu_data.vpercpu[cpu].adj_sched_time =
current->se.sum_exec_runtime - sched_clock();
}
+#endif
}
#ifdef CONFIG_SMP
--
1.7.4
next prev parent reply other threads:[~2011-12-12 21:20 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-12 19:36 [PATCH 0/2] Add a thread cpu time implementation to vDSO Arun Sharma
2011-12-12 19:36 ` [PATCH 1/2] Extend VVAR support to multiple pages Arun Sharma
2011-12-12 19:36 ` [PATCH 2/2] Add a thread cpu time implementation to vDSO Arun Sharma
2011-12-12 20:13 ` Eric Dumazet
2011-12-12 21:19 ` Arun Sharma [this message]
2011-12-12 21:27 ` Eric Dumazet
2011-12-12 21:33 ` Andrew Lutomirski
2011-12-12 22:14 ` Arun Sharma
2011-12-13 8:52 ` Peter Zijlstra
2011-12-13 18:15 ` Arun Sharma
2011-12-13 18:53 ` Peter Zijlstra
2011-12-12 20:15 ` Andrew Lutomirski
2011-12-12 22:49 ` Arun Sharma
2011-12-12 23:01 ` Andrew Lutomirski
2011-12-13 0:40 ` Arun Sharma
2011-12-12 23:09 ` john stultz
2011-12-12 23:20 ` Arun Sharma
2011-12-12 23:32 ` john stultz
2011-12-12 23:41 ` Andrew Lutomirski
2011-12-12 23:52 ` john stultz
2011-12-13 0:26 ` Arun Sharma
-- strict thread matches above, loose matches on Subject: below --
2011-12-19 19:51 [PATCH 0/2] Add a thread cpu time implementation to vDSO (v2) Arun Sharma
2011-12-19 19:51 ` [PATCH 2/2] Add a thread cpu time implementation to vDSO Arun Sharma
2011-12-19 19:58 ` Arun Sharma
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=4EE66FE9.1050202@fb.com \
--to=asharma@fb.com \
--cc=eric.dumazet@gmail.com \
--cc=johnstul@us.ibm.com \
--cc=kumar@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@MIT.EDU \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.