From: george anzinger <george@mvista.com>
To: owensjc@bellatlantic.net
Cc: "'Matti Aarnio'" <matti.aarnio@zmailer.org>,
mingo@elte.hu, linux-kernel@vger.kernel.org
Subject: Re: O(1) scheduler ver H6 - more straightforward timeslice macros
Date: Mon, 14 Jan 2002 10:59:08 -0800 [thread overview]
Message-ID: <3C432A7C.893D139@mvista.com> (raw)
In-Reply-To: <000001c19bb7$20756710$0100a8c0@jcowens.net>
"James C. Owens" wrote:
>
> > -----Original Message-----
> > From: Matti Aarnio [mailto:matti.aarnio@zmailer.org]
> > Sent: Saturday, January 12, 2002 5:00 PM
> > To: James C. Owens
> > Cc: mingo@elte.hu; linux-kernel@vger.kernel.org
> > Subject: Re: O(1) scheduler ver H6 - more straightforward timeslice
> > macros
> >
> >
> > On Sat, Jan 12, 2002 at 02:16:08PM -0500, James C. Owens wrote:
> > > Ingo,
> > >
> > > I like the new scheduler. It seems like the timeslice
> > macros in sched.h
> > > could be more straighforward - i.e. instead of
> >
> > (I quote too much, but to illustriate the point...)
> >
> > > #define PRIO_TO_TIMESLICE(p) \
> > > (((
> > (MAX_USER_PRIO-1-USER_PRIO(p))*(MAX_TIMESLICE-MIN_TIMESLICE) + \
> > > MAX_USER_PRIO-1) / MAX_USER_PRIO) + MIN_TIMESLICE)
> > >
> > > #define RT_PRIO_TO_TIMESLICE(p) \
> > > ((( (MAX_RT_PRIO-(p)-1)*(MAX_TIMESLICE-MIN_TIMESLICE) + \
> > > MAX_RT_PRIO-1) / MAX_RT_PRIO) + MIN_TIMESLICE)
> > >
> > > why not
> > >
> > > #define PRIO_TO_TIMESLICE(p) \
> > > (MAX_TIMESLICE -
> > > (USER_PRIO(p)/(MAX_USER_PRIO-1))*(MAX_TIMESLICE-MIN_TIMESLICE))
> > >
> > > #define RT_PRIO_TO_TIMESLICE(p) \
> > > (MAX_TIMESLICE -
> > (p/(MAX_RT_PRIO-1))*(MAX_TIMESLICE-MIN_TIMESLICE))
> > >
> > >
> > > The second way seems simpler to me, and really illustrates
> > what you are
> > > doing in a more straightforward manner.
> >
> > Except that the math is INTEGER, not floating-point,
> > which means that this way you loose precission.
> >
> > You HAVE TO do multiplications first, only then (finally)
> > the division.
> >
> > Depending the value-spaces, small-enough value-spaces might be
> > turnable into table mappings. However that has lots of
> > dependencies
> > in hardware architecture, e.g. memory access speeds, cache
> > pollution,
> > speed of multiply/divide operations, etc.
> >
> > If dividers/multipliers are constants, and powers of two, the math
> > can happen with constant shifts, which are fast at all systems.
> > If not, things get rather complicated. (And thus a careless -1,
> > or lack of one, may be costly.)
> >
> [snip]
> > /Matti Aarnio
> >
>
> Point well made. How about
>
> #define PRIO_TO_TIMESLICE(p) \
> (MAX_TIMESLICE -
> ((USER_PRIO(p)*(MAX_TIMESLICE-MIN_TIMESLICE))/(MAX_USER_PRIO-1)))
>
> #define RT_PRIO_TO_TIMESLICE(p) \
> (MAX_TIMESLICE - ((p*(MAX_TIMESLICE-MIN_TIMESLICE))/(MAX_RT_PRIO-1)))
>
> If people agree with this, I'll submit a new diff (with the right options).
>
> Jim Owens
If performance is important here we could eliminate the "/" thusly:
#define SC 24 // Change as needed to get precision and fit in 32 bits
#define SC_USER_FACTOR
((MAX_TIMESLICE-MIN_TIMESLICE)<<SC)/(MAX_USER_PRIO-1) // a constant
#define PRIO_TO_TIMESLICE(p) \
(MAX_TIMESLICE - ((USER_PRIO(p) * (SC_USER_FACTOR))>>SC
To eliminate the ">>" one could go to SC=32 and then just take the high
32-bits of the mpy. Taking the high 32-bits of mpy (which gives
64-bits) requires asm, but SC_USER_FACTOR would be:
#define SC_USER_FACTOR \
(long)((long long) (MAX_TIMESLICE-MIN_TIMESLICE)<<SC)/(long
long)(MAX_USER_PRIO-1)
SC=32 can be used as long as
(MAX_TIMESLICE-MIN_TIMESLICE)<(MAX_USER_PRIO-1)
--
George george@mvista.com
High-res-timers: http://sourceforge.net/projects/high-res-timers/
Real time sched: http://sourceforge.net/projects/rtsched/
prev parent reply other threads:[~2002-01-14 19:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-12 19:16 O(1) scheduler ver H6 - more straightforward timeslice macros James C. Owens
2002-01-12 21:59 ` Matti Aarnio
2002-01-12 22:18 ` James C. Owens
2002-01-13 18:08 ` Ingo Molnar
2002-01-13 18:42 ` James C. Owens
2002-01-13 20:55 ` Ingo Molnar
2002-01-14 18:59 ` george anzinger [this message]
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=3C432A7C.893D139@mvista.com \
--to=george@mvista.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matti.aarnio@zmailer.org \
--cc=mingo@elte.hu \
--cc=owensjc@bellatlantic.net \
/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.