The comment and the actual macros are inconsistent.
positive number * (19-n) is a decreasing function of n!
+ * The higher a process's priority, the bigger timeslices
+ * it gets during one round of execution. But even the lowest
+ * priority process gets MIN_TIMESLICE worth of execution time.
+ */
-#define NICE_TO_TIMESLICE(n) (MIN_TIMESLICE + \
- ((MAX_TIMESLICE - MIN_TIMESLICE) * (19 - (n))) / 39)
+#define NICE_TO_TIMESLICE(n) (MIN_TIMESLICE + \
+ ((MAX_TIMESLICE - MIN_TIMESLICE) * (19-(n))) / 39)
I still suggest a different set as faster and more readable at least to
me. Just two operations instead of 4!
#define NICE_TO_TIMESLICE(n) (((n)+21)*(HZ/10)) // should be positive!
#define MAX_TIMESLICE NICE_TO_TIMESLICE(19)
#define MIN_TIMESLICE NICE_TO_TIMESLICE(-20)
with later tweaking done in the function, like (((n)+22)*(HZ/25)) instead.
Alexei
On Wed, 16 Jan 2002, Alexei Podtelezhnikov wrote:
>
> The comment and the actual macros are inconsistent.
> positive number * (19-n) is a decreasing function of n!
# man nice
> + * The higher a process's priority, the bigger timeslices
> + * it gets during one round of execution. But even the lowest
> + * priority process gets MIN_TIMESLICE worth of execution time.
> + */
>
> -#define NICE_TO_TIMESLICE(n) (MIN_TIMESLICE + \
> - ((MAX_TIMESLICE - MIN_TIMESLICE) * (19 - (n))) / 39)
> +#define NICE_TO_TIMESLICE(n) (MIN_TIMESLICE + \
> + ((MAX_TIMESLICE - MIN_TIMESLICE) * (19-(n))) / 39)
>
> I still suggest a different set as faster and more readable at least to
> me. Just two operations instead of 4!
this seems quite readable to me, it's the equation at page 1 of any know
linear geometry book.
- Davide
man nice helped. Thanks!
On Wed, 16 Jan 2002, Davide Libenzi wrote:
> On Wed, 16 Jan 2002, Alexei Podtelezhnikov wrote:
>
> >
> > The comment and the actual macros are inconsistent.
> > positive number * (19-n) is a decreasing function of n!
>
> # man nice
>
>
> > + * The higher a process's priority, the bigger timeslices
> > + * it gets during one round of execution. But even the lowest
> > + * priority process gets MIN_TIMESLICE worth of execution time.
> > + */
> >
> > -#define NICE_TO_TIMESLICE(n) (MIN_TIMESLICE + \
> > - ((MAX_TIMESLICE - MIN_TIMESLICE) * (19 - (n))) / 39)
> > +#define NICE_TO_TIMESLICE(n) (MIN_TIMESLICE + \
> > + ((MAX_TIMESLICE - MIN_TIMESLICE) * (19-(n))) / 39)
> >
> > I still suggest a different set as faster and more readable at least to
> > me. Just two operations instead of 4!
>
> this seems quite readable to me, it's the equation at page 1 of any know
> linear geometry book.
>
>
>
>
> - Davide
>
>
>
On Wed, 16 Jan 2002, Alexei Podtelezhnikov wrote:
> man nice helped. Thanks!
>
> On Wed, 16 Jan 2002, Davide Libenzi wrote:
>
> > On Wed, 16 Jan 2002, Alexei Podtelezhnikov wrote:
> >
> > >
> > > The comment and the actual macros are inconsistent.
> > > positive number * (19-n) is a decreasing function of n!
> >
> > # man nice
> >
> >
> > > + * The higher a process's priority, the bigger timeslices
> > > + * it gets during one round of execution. But even the lowest
> > > + * priority process gets MIN_TIMESLICE worth of execution time.
> > > + */
> > >
> > > -#define NICE_TO_TIMESLICE(n) (MIN_TIMESLICE + \
> > > - ((MAX_TIMESLICE - MIN_TIMESLICE) * (19 - (n))) / 39)
> > > +#define NICE_TO_TIMESLICE(n) (MIN_TIMESLICE + \
> > > + ((MAX_TIMESLICE - MIN_TIMESLICE) * (19-(n))) / 39)
> > >
> > > I still suggest a different set as faster and more readable at least to
> > > me. Just two operations instead of 4!
> >
> > this seems quite readable to me, it's the equation at page 1 of any know
> > linear geometry book.
and this macro gets called about every 80ms, that is nothing. try to run a
cycle counter between the two implementation, get the time difference
using the CPU speed and weight it with 80ms. you'll get a percent that
compared to that, the probability of having snow in Miami in August is a
big number :-)
- Davide
On Wed, 16 Jan 2002, Alexei Podtelezhnikov wrote:
> I still suggest a different set as faster and more readable at least to
> me. Just two operations instead of 4!
>
> #define NICE_TO_TIMESLICE(n) (((n)+21)*(HZ/10)) // should be positive!
> #define MAX_TIMESLICE NICE_TO_TIMESLICE(19)
> #define MIN_TIMESLICE NICE_TO_TIMESLICE(-20)
Looks more readable. I wouldn't bet on faster, but definitely more
readable.
--
bill davidsen <[email protected]>
CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.