public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Eric Dumazet <dada1@cosmosbay.com>
Cc: Andi Kleen <ak@suse.de>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] group xtime, xtime_lock, wall_to_monotonic, avenrun, calc_load_count fields together in ktimed
Date: Fri, 8 Dec 2006 21:46:25 -0800	[thread overview]
Message-ID: <20061208214625.90e010ae.akpm@osdl.org> (raw)
In-Reply-To: <200612081752.09749.dada1@cosmosbay.com>

On Fri, 8 Dec 2006 17:52:09 +0100
Eric Dumazet <dada1@cosmosbay.com> wrote:

> This patch introduces a new structure called ktimed (Kernel Time Data), where 
> some time keeping related variables are put together to share as few cache 
> lines as possible. This avoid some false sharing, (since linker could put 
> calc_load_count in a *random* cache line for example)
> 
> I also optimized calc_load() to not always call count_active_tasks() :
> It should call it only once every 5 seconds (LOAD_FREQ=5*HZ)
> 
> Note : x86_64 was using an arch specific placement of __xtime and __xtime_lock 
> (see arch/x86_64/kernel/vmlinux.lds.S). (vsyscall stuff)
> It is now using a specific placement of __ktimed, since xtime and xtime_lock 
> are now fields from __ktimed.
> 
> Note : I failed to move jiffies64 as well in ktimed : too many changes needed 
> because of jiffies aliasing (and endianess), but it could be done.
> 

Sounds like you have about three patches there.

<save attachment, read from file, s/^/> />

>  
> -extern struct timespec xtime;
> -extern struct timespec wall_to_monotonic;
> -extern seqlock_t xtime_lock;
> +/*
> + * define a structure to keep all fields close to each others.
> + */
> +struct ktimed_struct {
> +	struct timespec _xtime;
> +	struct timespec wall_to_monotonic;
> +	seqlock_t lock;
> +	unsigned long avenrun[3];
> +	int calc_load_count;
> +};

crappy name, but I guess it doesn't matter as nobody will use it at this
stage.  But...

> +extern struct ktimed_struct ktimed;
> +#define xtime             ktimed._xtime
> +#define wall_to_monotonic ktimed.wall_to_monotonic
> +#define xtime_lock        ktimed.lock
> +#define avenrun           ktimed.avenrun

They'll use these instead.

Frankly, I think we'd be better off removing these macros and, longer-term,
use

	write_seqlock(time_data.xtime_lock);

The approach you have here would be a good transition-period thing.

>  void timekeeping_init(void);
>  
> --- linux-2.6.19/kernel/timer.c	2006-12-08 11:50:11.000000000 +0100
> +++ linux-2.6.19-ed/kernel/timer.c	2006-12-08 18:13:24.000000000 +0100
> @@ -570,11 +570,13 @@ found:
>   * however, we will ALWAYS keep the tv_nsec part positive so we can use
>   * the usual normalization.
>   */
> -struct timespec xtime __attribute__ ((aligned (16)));
> -struct timespec wall_to_monotonic __attribute__ ((aligned (16)));
> -
> -EXPORT_SYMBOL(xtime);
> -
> +#ifndef ARCH_HAVE_KTIMED

argh, another ARCH_HAVE_MESS.  Due to the x86_64 vsyscall code.

Could you please see if we can nuke this by making
kernel/timer.c:xtime_lock use attribute(weak)?  In a separate patch ;)

> +struct ktimed_struct ktimed __cacheline_aligned = {
> +	.lock = __SEQLOCK_UNLOCKED(ktimed.lock),
> +	.calc_load_count = LOAD_FREQ,
> +};
> +EXPORT_SYMBOL(ktimed);
> +#endif
>  
>  /* XXX - all of this timekeeping code should be later moved to time.c */
>  #include <linux/clocksource.h>
> @@ -995,9 +997,6 @@ static unsigned long count_active_tasks(
>   *
>   * Requires xtime_lock to access.
>   */
> -unsigned long avenrun[3];
> -
> -EXPORT_SYMBOL(avenrun);
>  
>  /*
>   * calc_load - given tick count, update the avenrun load estimates.
> @@ -1006,27 +1005,21 @@ EXPORT_SYMBOL(avenrun);
>  static inline void calc_load(unsigned long ticks)
>  {
>  	unsigned long active_tasks; /* fixed-point */
> -	static int count = LOAD_FREQ;
>  
> -	active_tasks = count_active_tasks();
> -	for (count -= ticks; count < 0; count += LOAD_FREQ) {
> -		CALC_LOAD(avenrun[0], EXP_1, active_tasks);
> -		CALC_LOAD(avenrun[1], EXP_5, active_tasks);
> -		CALC_LOAD(avenrun[2], EXP_15, active_tasks);
> +	ktimed.calc_load_count -= ticks;
> +
> +	if (unlikely(ktimed.calc_load_count < 0)) {
> +		active_tasks = count_active_tasks();
> +		do {
> +			ktimed.calc_load_count += LOAD_FREQ;
> +			CALC_LOAD(avenrun[0], EXP_1, active_tasks);
> +			CALC_LOAD(avenrun[1], EXP_5, active_tasks);
> +			CALC_LOAD(avenrun[2], EXP_15, active_tasks);
> +		} while (ktimed.calc_load_count < 0);
>  	}
>  }
>  
> ...
>
> +extern struct ktimed_struct __ktimed;
> +#define __xtime_lock __ktimed.lock
> +#define __xtime      __ktimed._xtime
>  
>  /* kernel space (writeable) */
>  extern struct vxtime_data vxtime;
>  extern int vgetcpu_mode;
>  extern struct timezone sys_tz;
>  extern int sysctl_vsyscall;
> -extern seqlock_t xtime_lock;
>  
> -extern int sysctl_vsyscall;
> -
> -#define ARCH_HAVE_XTIME_LOCK 1
> +#define ARCH_HAVE_KTIMED 1
>  

hm, the patch seems to transform a mess into a mess.  I guess it's a messy
problem.

I agree that aggregating all the time-related things into a struct like
this makes some sense.  As does aggregating them all into a similar-looking
namespace, but that'd probably be too intrusive - too late for that.



  reply	other threads:[~2006-12-09  5:46 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-03  5:50 [PATCH] Export current_is_keventd() for libphy Ben Collins
2006-12-03  9:16 ` Andrew Morton
2006-12-04 19:17   ` Steve Fox
2006-12-05 18:05     ` Maciej W. Rozycki
2006-12-05 17:48   ` Maciej W. Rozycki
2006-12-05 18:07     ` Linus Torvalds
2006-12-05 19:31       ` Andrew Morton
2006-12-05 18:57     ` Andy Fleming
2006-12-06 12:31       ` Maciej W. Rozycki
2006-12-05 20:39     ` Andrew Morton
2006-12-05 20:59       ` Andy Fleming
2006-12-05 21:26         ` Andrew Morton
2006-12-05 21:37           ` Roland Dreier
2006-12-05 21:57             ` Andrew Morton
2006-12-05 23:49               ` Roland Dreier
2006-12-05 23:52               ` Roland Dreier
2006-12-06 15:25               ` Maciej W. Rozycki
2006-12-06 15:57                 ` Andrew Morton
2006-12-06 17:17                   ` Linus Torvalds
2006-12-06 17:43                     ` David Howells
2006-12-06 17:50                       ` Jeff Garzik
2006-12-06 18:07                         ` Linus Torvalds
2006-12-06 17:53                       ` Linus Torvalds
2006-12-06 17:58                         ` Linus Torvalds
2006-12-06 18:33                           ` Linus Torvalds
2006-12-06 18:37                             ` Linus Torvalds
2006-12-06 18:43                             ` David Howells
2006-12-06 19:02                               ` Linus Torvalds
2006-12-06 18:02                         ` David Howells
2006-12-07  1:21                     ` Linus Torvalds
2006-12-07  6:42                       ` Andrew Morton
2006-12-07  7:49                         ` Andrew Morton
2006-12-07 10:29                           ` David Howells
2006-12-07 10:42                             ` Andrew Morton
2006-12-07 17:05                               ` Jeff Garzik
2006-12-07 17:57                                 ` Andrew Morton
2006-12-07 18:17                                   ` Andrew Morton
2006-12-08 16:52                                   ` [PATCH] group xtime, xtime_lock, wall_to_monotonic, avenrun, calc_load_count fields together in ktimed Eric Dumazet
2006-12-09  5:46                                     ` Andrew Morton [this message]
2006-12-09  6:07                                       ` Randy Dunlap
2006-12-11 20:44                                       ` Eric Dumazet
2006-12-11 22:00                                         ` Andrew Morton
2006-12-13 21:26                                     ` [PATCH] Introduce time_data, a new structure to hold jiffies, xtime, xtime_lock, wall_to_monotonic, calc_load_count and avenrun Eric Dumazet
2006-12-15  5:24                                       ` Andrew Morton
2006-12-15 11:21                                         ` Eric Dumazet
2006-12-15 16:21                                       ` Eric Dumazet
2006-12-07 18:08                                 ` [PATCH] Export current_is_keventd() for libphy Maciej W. Rozycki
2006-12-07 18:59                                 ` Andy Fleming
2006-12-07 16:49                         ` Linus Torvalds
2006-12-07 17:52                           ` Andrew Morton
2006-12-07 18:01                             ` Linus Torvalds
2006-12-07 18:16                               ` Andrew Morton
2006-12-07 18:27                                 ` Linus Torvalds
2006-12-07 15:28                       ` Maciej W. Rozycki

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=20061208214625.90e010ae.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=ak@suse.de \
    --cc=dada1@cosmosbay.com \
    --cc=linux-kernel@vger.kernel.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