lkml.org 
[lkml]   [2011]   [Dec]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 2/2] Add a thread cpu time implementation to vDSO
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




\
 
 \ /
  Last update: 2011-12-12 22:23    [from the cache]
©2003-2011 Jasper Spaans