From: Peter Zijlstra <peterz@infradead.org>
To: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Ray Lee <ray-lk@madrabbit.org>,
adobriyan@gmail.com, Ingo Molnar <mingo@elte.hu>,
"Zhang, Yanmin" <yanmin_zhang@linux.intel.com>,
Dhaval Giani <dhaval@linux.vnet.ibm.com>,
LKML <linux-kernel@vger.kernel.org>,
Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>,
Aneesh Kumar KV <aneesh.kumar@linux.vnet.ibm.com>,
Balbir Singh <balbir@in.ibm.com>,
Chris Friesen <cfriesen@nortel.com>
Subject: Re: VolanoMark regression with 2.6.27-rc1
Date: Thu, 21 Aug 2008 10:17:35 +0200 [thread overview]
Message-ID: <1219306655.8651.90.camel@twins> (raw)
In-Reply-To: <200808211611.17889.nickpiggin@yahoo.com.au>
On Thu, 2008-08-21 at 16:11 +1000, Nick Piggin wrote:
> On Thursday 21 August 2008 06:56, Peter Zijlstra wrote:
> > On Wed, 2008-08-20 at 22:30 +0200, Peter Zijlstra wrote:
>
> > > works for the above example, but when I make it long long, so as to
> > > match the longest supported type, it goes boom again - for as of yet
> > > unknown reasons.
> >
> > Ok, people pointed out I got my promotion rules mixed up, I casted the
> > result of the division to signed, instead of ending up with a signed
> > division.
> >
> > #define avg(x, y) ({ \
> > typeof(x) _avg1 = (x); \
> > typeof(y) _avg2 = (y); \
> > (void) (&_avg1 == &_avg2); \
> > (typeof(x))(_avg1 + ((long long)_avg2 - _avg1)/2); })
> >
> > seems to work.
>
> Right, I guess that will work, but unfortunately the code gen on 32-bit
> is a monstrosity. If you're going to cast to 64-bit anyway, we might as
> well then just do the normal add rather than playing the game to avoid
> overflow.
>
> Secondly, this is operating on the fixed point scaled load numbers, so in
> the case of the scheduler I wouldn't worry too much about rounding... also
> in most integer operations, rounding down is less surprising than rounding
> up like the last code did.
>
> I still don't know whether it is appropriate to put it into kernel.h
> (because of rounding, and variability when it comes to what type size will
> hold the sum of parameters), but for the scheduler, I would use this:
>
> ((unsigned long long)a + b) / 2;
Right - anyway the point is moot - as Yanmin says it still sucks rocks.
But since I couldn't let it rest :-)
---
Index: linux-2.6/include/linux/kernel.h
===================================================================
--- linux-2.6.orig/include/linux/kernel.h
+++ linux-2.6/include/linux/kernel.h
@@ -367,6 +367,45 @@ static inline char *pack_hex_byte(char *
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
+#define __avg_t(type, x, y) ({ \
+ typeof(x) __avg1 = (x); \
+ typeof(y) __avg2 = (y); \
+ __avg1 + ((type)(__avg2 - __avg1))/2; })
+
+extern void avg_unknown_size(void);
+
+#define __avg(x, y) ({ \
+ typeof(x) ret; \
+ switch (sizeof(ret)) { \
+ case 1: \
+ ret = __avg_t(s8, x, y); \
+ break; \
+ case 2: \
+ ret = __avg_t(s16, x, y); \
+ break; \
+ case 4: \
+ ret = __avg_t(s32, x, y); \
+ break; \
+ case 8: \
+ ret = __avg_t(s64, x, y); \
+ break; \
+ default: \
+ avg_unknown_size(); \
+ break; \
+ } \
+ ret; })
+
+#define avg(x, y) ({ \
+ typeof(x) _avg1 = (x); \
+ typeof(y) _avg2 = (y); \
+ (void) (&_avg1 == &_avg2); \
+ __avg(_avg1, _avg2); })
+
+#define avg_t(type, x, y) ({ \
+ type _avg1 = (x); \
+ type _avg2 = (y); \
+ __avg(_avg1, _avg2); })
+
/**
* clamp - return a value clamped to a given range with strict typechecking
* @val: current value
next prev parent reply other threads:[~2008-08-21 8:18 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-31 3:20 VolanoMark regression with 2.6.27-rc1 Zhang, Yanmin
2008-07-31 7:31 ` Zhang, Yanmin
2008-07-31 7:39 ` Peter Zijlstra
2008-07-31 7:49 ` Zhang, Yanmin
2008-08-01 0:39 ` Zhang, Yanmin
2008-08-01 2:35 ` Miao Xie
2008-08-01 3:08 ` Zhang, Yanmin
2008-08-01 5:14 ` Dhaval Giani
2008-08-04 5:04 ` Zhang, Yanmin
2008-08-04 5:22 ` Dhaval Giani
2008-08-04 5:37 ` Zhang, Yanmin
2008-08-04 5:53 ` Dhaval Giani
2008-08-04 6:26 ` Peter Zijlstra
2008-08-04 6:26 ` Peter Zijlstra
2008-08-04 7:05 ` Dhaval Giani
2008-08-04 7:12 ` Peter Zijlstra
2030-08-06 3:26 ` Zhang, Yanmin
2008-08-08 7:30 ` Peter Zijlstra
[not found] ` <20080811185008.GA29291@linux.vnet.ibm.com>
[not found] ` <1912726331.25608.235.camel@ymzhang>
[not found] ` <20080817115035.GA32223@linux.vnet.ibm.com>
[not found] ` <20080818052155.GA5063@linux.vnet.ibm.com>
2008-08-20 7:24 ` Zhang, Yanmin
2008-08-20 7:41 ` Peter Zijlstra
2008-08-20 10:51 ` Ingo Molnar
2008-08-20 13:32 ` Peter Zijlstra
2008-08-20 13:47 ` Ingo Molnar
2008-08-21 2:25 ` Zhang, Yanmin
2008-08-21 6:16 ` Ingo Molnar
2008-08-21 6:48 ` Zhang, Yanmin
2008-08-29 3:35 ` Zhang, Yanmin
2008-08-29 3:38 ` Zhang, Yanmin
2008-08-20 14:32 ` adobriyan
2008-08-20 14:33 ` Peter Zijlstra
2008-08-20 15:10 ` Nick Piggin
2008-08-20 15:15 ` Peter Zijlstra
2008-08-20 16:29 ` Ray Lee
2008-08-20 16:51 ` Peter Zijlstra
2008-08-20 17:21 ` Peter Zijlstra
2008-08-20 17:55 ` Nick Piggin
2008-08-20 18:15 ` Ray Lee
2008-08-20 20:30 ` Peter Zijlstra
2008-08-20 20:56 ` Peter Zijlstra
2008-08-21 6:11 ` Nick Piggin
2008-08-21 8:17 ` Peter Zijlstra [this message]
2008-08-21 6:15 ` Ingo Molnar
2008-08-20 20:58 ` Ray Lee
2008-08-20 21:04 ` Peter Zijlstra
2008-08-21 6:12 ` Ingo Molnar
2030-08-13 8:50 ` Zhang, Yanmin
2008-08-04 6:54 ` Peter Zijlstra
2008-08-15 15:37 ` Ingo Molnar
2008-08-01 12:25 ` Hugh Dickins
2008-08-04 0:54 ` Zhang, Yanmin
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=1219306655.8651.90.camel@twins \
--to=peterz@infradead.org \
--cc=adobriyan@gmail.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=balbir@in.ibm.com \
--cc=cfriesen@nortel.com \
--cc=dhaval@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=nickpiggin@yahoo.com.au \
--cc=ray-lk@madrabbit.org \
--cc=vatsa@linux.vnet.ibm.com \
--cc=yanmin_zhang@linux.intel.com \
/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.