Skip to contentSkip to conversation

Runaway cron task on 2.5.63/4 bk?

DISCUSSION Felipe Alfaro Solana 7 participants 17 messages Mar 10, 2003 – Mar 12, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

----- Original Message -----
From: Andrew Morton <[email protected]>
Date: Mon, 10 Mar 2003 14:29:44 -0800
To: george anzinger <[email protected]>
Subject: Re: Runaway cron task on 2.5.63/4 bk?

Quoted 7 lines

If an app wants to sleep forever, calling

	while (1) 
		sleep(MAX_INT); 

seems like a reasonable approach. I'd expect quite a lot of applications would be doing that.

why not sleep(0)?

Felipe

Signature · 5 lines
______________________________________________
http://www.linuxmail.org/
Now with e-mail forwarding for only US$5.95/yr

Powered by Outblaze
#1 lore raw
Quoted 2 lines · Felipe Alfaro Solana

why not sleep(0)?

I think a much more likely (and correct) usage for big sleep values is more something like this:

	do_with_timeout(xxx, int timeout)
	{
		struct timespec ts;

		... set up some async event ..
		ts.tv_nsec = 0;
		ts.tv_sec = timeout;
		while (nanosleep(&ts, &ts)) {
			if (async event happened)
				return happy;
		}
		.. tear down the async event if it didn't happen ..
	}

and here the natural thing to do in user space is to just make the "no timeout" case be a huge value.

At which point it is a _bug_ in the kernel if we return early with some random error code.

Linus

#2 lore raw

Ok, here is what I have. I changed nano sleep to use a local 64-bit value for the target expire time in jiffies. As much as MAX-INT/2-1 will be put in the timer at any one time. It loops till the target time is met or exceeded. The changes affect (clock)nanosleep only and not timers (they still error out for large values).

Issues: The conversion of timespec to jiffies_64 is most easily done by the asm mpy instruction, which results in the required 64 bit result, but C doesn't want to do this sort of thing. I included a header file, originally written for the high-res code, that makes several of these functions available, both in an i386 asm version and a generic version. These functions were done mostly to do scaled math (hence the name sc_math.h) so I also included a "txt" file for the Documentation directory that talks about scaled math and, to some extent, about the routines in sc_math.h.

What do you think?

Oh, the code passes the tests I have, but I have not tried to test for very large sleep times. I can think of a couple of test that should be done.... tomorrow.

-g

Quoted 29 lines · Linus Torvalds
Quoted 2 lines · Felipe Alfaro Solana

why not sleep(0)?

I think a much more likely (and correct) usage for big sleep values is more something like this:

	do_with_timeout(xxx, int timeout)
	{
		struct timespec ts;

		... set up some async event ..
		ts.tv_nsec = 0;
		ts.tv_sec = timeout;
		while (nanosleep(&ts, &ts)) {
			if (async event happened)
				return happy;
		}
		.. tear down the async event if it didn't happen ..
	}

and here the natural thing to do in user space is to just make the "no timeout" case be a huge value.

At which point it is a _bug_ in the kernel if we return early with some random error code.

Linus

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
Documentation/scaled_math.txt +169 -0
diff -urP -I '\$Id:.*Exp \$' -X /usr/src/patch.exclude linux-2.5.64-kb/Documentation/scaled_math.txt linux/Documentation/scaled_math.txt
@@ -0,0 +1,169 @@
+This file gives a bit of information on scaling integers, the math
+involved, and the considerations needed to decide if and how to use
+scaled math. 
+
+What is it anyway?
+
+Scaled math is a method of doing integer math which allows you to:
+
+A.) Work with fractions in integer math.
+B.) Use MPY instead of DIV (much faster).
+C.) To reduce round off (or digitizing) errors.
+
+Basically, in scaled math you would replace an equation of this sort:
+
+r = foo / bar                or r = foo * top / bar
+
+with this:
+
+r = (foo * SC) / (bar * SC)  or r = (foo * top *SC) / (bar * SC)
+
+Regrouping these:
+
+r = foo * (SC / bar) / SC    or r = foo * ((top *  SC) / bar) / SC
+
+SC is the scale factor.  We choose SC carefully to retain the most bits
+in the calculation and to make the math easy.  We make the math easy by
+making SC be a power of 2 so the * SC and / SC operations are just
+shifts.
+
+
+How does it accomplish all this?
+
+The best way to show the benefits of scaled math is to go through an
+example.  Here is a common problem: During boot up of an 800MHZ machine
+we measure the speed of the machine against the time base.  In the case
+of the i386 machine with a TSC this means we program the PIT for a fixed
+time interval and measure the difference in TSC values over this
+interval.  Suppose we measure this over 0.010 seconds (10 ms).  With
+this particular machine we would get something like 8,000,000 (call this
+TSC-M).  We want to use this number to convert TSC counts to micro
+seconds.  So the math is:
+
+usec = tsccount * 0.01 * 1000000 / TSC-M   or
+usec = tsccount * 10000 / TSC-M
+
+Now the first thing to notice here is that (10000 / TSC-M) is less than
+one and, if we precalculated it we would loose big time.  We might try
+precalculating (TSC-M / 100000) but this also has problems.  First it
+would require a "div" each time we wanted to convert a "tsccount" to
+micro seconds.  The second problem is that the result of this
+precalculation would be on the order of 80, or only 6 to 7 bits so we
+would loose a lot of precision.
+
+The scaled way to do this is to precalculate ((10000 * SC) / TSC-M).  In
+fact this is what is done in the i386 time code.  In this case SC is
+(2**32).  This allows micro seconds to be calculated as:
+
+usec = tsccount * ((10000 * SC) / TSC-M) / SC
+
+where ((10000 * SC) / TSC-M) is a precalculated constant and "/ SC"
+becomes a right shift of 32 bits.  The easy way to do this is to do a
+simple "mul" instruction and take the high order bits as the result.
+I.e. the right shift doesn't even need to be done in this case.
+
+What have we gained here?
+
+The precision is much higher.  The constant will be on the order of
+5,368,709 so we have about 1 bit in 5 million of precision, not bad.
+
+We now do a multiply to do the conversion which is much faster than the
+divide.  Note, also, if we happen to want nano seconds instead of micro
+seconds we could just change the constant term to:
+
+(10000000 * SC) / TSC-M
+
+which has even more precision.  Note here that we are really trying to
+multiply the TSC count by something like 1.25 (or divide it by 0.8) both
+of which are fractions that would loose most of there precision with out
+scaling. 
+
+How to choose SC:
+
+SC has to be chosen carefully to avoid both underflow and overflow.
+
+With the routines provided in the sc_math.h file, the calculations expand
+for a brief moment to 64-bits and then are reduced back to 32-bits.  For
+example, the calculation of ((10000 * SC) / TSC-M) will shift "10000"
+left 32 bits to form a 64-bit numerator for the divide by TSC-M.  SC
+must be chosen so that the result of the divide is no more than 32-bits
+(i.e. does not overflow).  In our example, this defines the slowest
+machine we can handle (10,000 tsc counts in 0.01 sec or 1MHZ).
+
+Like wise, if SC is too small, the result will be too small and
+precision will be lost.
+
+Notes on the sc_math.h functions:
+
+What the sc_math.h functions do is to provide routines that allow usage
+of the ability of the hardware to multiply two integers and return a
+result that is twice the length of the original integers.  At the same
+time it provides access to the divide instruction which can divide a
+64-bit numerator by a 32-bit denominator and return a 32-bit quotient and
+remainder. 
+
+In addition, to help with the scaling, routines are provide that combine
+the common scaling shift operation with the multiply or divide.
+
+Since (2**32) is a common scaling, functions to deal with it most
+efficiently are provided.
+
+Functions that allow easy calculation of conversion constants at compile
+time are also provided.
+
+Details:
+
+All the functions work with unsigned long or unsigned long long.  We
+leave it for another day to do the signed versions.  Also, we have
+provided a generic sc_math.h file.  This begs for each 32-bit arch to
+supply an asm version which will be much more efficient.
+
+SC_32(x) given an integer (or long) returns  (unsigned long long)x<<32 
+SC_n(n,x) given an integer (or long) returns  (unsigned long long)x<<n
+
+These may be used to form constants at compile time, e.g.:
+
+unsigned long sc_constant = SC_n(24, (constant expression)) / constant;
+
+mpy_sc32(unsigned long a, unsigned long b); returns (a * b) >> 32
+
+mpy_sc24(unsigned long a, unsigned long b); returns (a * b) >> 24
+
+mpy_sc_n(const N, unsigned long a, unsigned long b); returns (a * b) >> N
+
+Note: N must be a constant here.
+
+div_sc32(unsigned long a, unsigned long b); returns (a << 32) / b
+
+div_sc24(unsigned long a, unsigned long b); returns (a << 24) / b
+
+div_sc_n(const N, unsigned long a, unsigned long b); returns (a << N) / b
+
+Note: N must be a constant here.
+
+In addition, the following functions provide access to the mpy and div
+instructions:
+
+mpy_l_X_l_ll(unsigned long mpy1, unsigned long mpy2); 
+returns (unsigned long long)(mpy1 * mpy2)
+
+mpy_l_X_l_h(unsigned long mpy1, unsigned long mpy2, unsigned long *hi);
+returns (unsigned long)(mpy1 * mpy2) & 0xffffffff  and 
+        (unsigned long)(mpy1 * mpy2) >> 32 in hi
+
+mpy_ll_X_l_ll(unsigned long long  mpy1, unsigned long mpy2);
+returns (unsigned long long)(mpy1 * mpy2)
+
+Note: The long long mpy1, this routine allows a string of mpys where it
+is undetermined where the result becomes long long.
+
+div_ll_X_l_rem(unsigned long long divs, unsigned long div, unsigned long *rem);
+returns (unsigned long)(divs/div) 
+with the remainder in rem
+
+div_long_long_rem() is an alias for the above.
+
+div_h_or_l_X_l_rem(unsigned long divh, unsigned long divl, 
+		   unsigned long div, unsigned long *rem)
+returns (unsigned long)((divh << 32) | divl) / div 
+with the remainder in rem
include/asm-generic/sc_math.h +311 -0

311 lines not on this page · raw message

include/asm-i386/sc_math.h +152 -0

152 lines not on this page · raw message

include/linux/thread_info.h +1 -1
diff -urP -I '\$Id:.*Exp \$' -X /usr/src/patch.exclude linux-2.5.64-kb/include/linux/thread_info.h linux/include/linux/thread_info.h
@@ -12,7 +12,7 @@
  */
 struct restart_block {
 	long (*fn)(struct restart_block *);
-	unsigned long arg0, arg1, arg2;
+	unsigned long arg0, arg1, arg2, arg3;
 };
 
 extern long do_no_restart_syscall(struct restart_block *parm);
kernel/posix-timers.c +45 -37

154 lines not on this page · raw message

Binary files linux-2.5.64-kb/lib/gen_crc32table and linux/lib/gen_crc32table differ Binary files linux-2.5.64-kb/scripts/docproc and linux/scripts/docproc differ Binary files linux-2.5.64-kb/scripts/fixdep and linux/scripts/fixdep differ
Binary files linux-2.5.64-kb/scripts/kallsyms and linux/scripts/kallsyms differ Binary files linux-2.5.64-kb/scripts/mk_elfconfig and linux/scripts/mk_elfconfig differ Binary files linux-2.5.64-kb/scripts/modpost and linux/scripts/modpost differ Binary files linux-2.5.64-kb/usr/gen_init_cpio and linux/usr/gen_init_cpio differ Binary files linux-2.5.64-kb/usr/initramfs_data.cpio.gz and linux/usr/initramfs_data.cpio.gz differ

#3 lore raw
Quoted 10 lines · george anzinger

Ok, here is what I have. I changed nano sleep to use a local 64-bit value for the target expire time in jiffies. As much as MAX-INT/2-1 will be put in the timer at any one time. It loops till the target time is met or exceeded. The changes affect (clock)nanosleep only and not timers (they still error out for large values).

Issues: The conversion of timespec to jiffies_64 is most easily done by the asm mpy instruction, which results in the required 64 bit result, but C doesn't want to do this sort of thing.

gcc will generate 64bit * 64bit multiplies without resorting to any library code and you can probably do the division with do_div().

#4 lore raw
Quoted 3 lines · Andrew Morton

gcc will generate 64bit * 64bit multiplies without resorting to any library code

However, gcc is unable to do-the-right-thing and generate 32x32->64 multiplies, or 32x64->64 multiplies, even though those are both a _lot_ faster than the full 64x64->64 case.

And in quite a _lot_ of cases, that's actually what you want. It might actually make sense to add a "do_mul()" thing to allow architectures to do these cases right, since gcc doesn't.

Quoted 1 line

and you can probably do the division with do_div().

Yes. This is the same issue - gcc will always promote a 64-bit divide to be _fully_ 64-bit, even if the mixed-size 64/32 -> [64,32] case is much faster and simpler. Which is why do_div() exists in the first place.

Linus

#5 lore raw
Quoted 10 lines · Linus Torvalds
Quoted 3 lines · Andrew Morton

gcc will generate 64bit * 64bit multiplies without resorting to any library code

However, gcc is unable to do-the-right-thing and generate 32x32->64 multiplies, or 32x64->64 multiplies, even though those are both a _lot_ faster than the full 64x64->64 case.

2.95.3 and 3.2.1 seem to do it right?

long a;
long b;
long long c;

void foo(void)

{
	c = a * b;
}
	.file	"t.c"
	.version	"01.01"

gcc2_compiled.:
.text
.align 4
.globl foo
.type foo,@function
foo:

	pushl %ebp
	movl %esp,%ebp
	movl a,%eax
	imull b,%eax
	movl %eax,c
	cltd
	movl %edx,c+4

.L2:
movl %ebp,%esp
popl %ebp
ret
.Lfe1:

	.size	 foo,.Lfe1-foo
	.comm	a,4,4
	.comm	b,4,4
	.comm	c,8,4
	.ident	"GCC: (GNU) 2.95.3 20010315 (release)"
#6 lore raw
Quoted 2 lines · Andrew Morton

2.95.3 and 3.2.1 seem to do it right?

Try the "64x32->64" version. gcc didn't use to get that one right, but maybe it does now.

Linus

#12 lore raw
In reply to Linus Torvalds
Quoted 12 lines · Linus Torvalds
Quoted 2 lines · Andrew Morton

gcc will generate 64bit * 64bit multiplies without resorting to any library code

However, gcc is unable to do-the-right-thing and generate 32x32->64 multiplies, or 32x64->64 multiplies, even though those are both a _lot_ faster than the full 64x64->64 case.

And in quite a _lot_ of cases, that's actually what you want. It might actually make sense to add a "do_mul()" thing to allow architectures to do these cases right, since gcc doesn't.

Quoted 6 lines
Quoted 1 line

and you can probably do the division with do_div().

Yes. This is the same issue - gcc will always promote a 64-bit divide to be _fully_ 64-bit, even if the mixed-size 64/32 -> [64,32] case is much faster and simpler. Which is why do_div() exists in the first place.

Often the 64/32 -> [32,32] is all that is needed and that is even faster if we could get to it.

Quoted 9 lines

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#7 lore raw
In reply to Linus Torvalds
Quoted 9 lines · Linus Torvalds
Quoted 2 lines · Andrew Morton

2.95.3 and 3.2.1 seem to do it right?

Try the "64x32->64" version. gcc didn't use to get that one right, but maybe it does now.

long a;
long long b;
long long c;

void foo(void)

{
	c = a * b;
}

It seems to get that wrong. At least, there are three multiplies in there. 3.2.1 is similar.

	.file	"t.c"
	.version	"01.01"

gcc2_compiled.:
.text
.align 4
.globl foo
.type foo,@function
foo:

	pushl %ebp
	movl %esp,%ebp
	subl $16,%esp
	pushl %esi
	pushl %ebx
	movl a,%eax
	movl %eax,%ebx
	movl %eax,%esi
	sarl $31,%esi
	movl %ebx,%eax
	mull b
	movl %eax,-8(%ebp)
	movl %edx,-4(%ebp)
	movl %ebx,%eax
	imull b+4,%eax
	addl %eax,%edx
	movl %edx,-4(%ebp)
	movl b,%eax
	imull %esi,%eax
	addl %eax,-4(%ebp)
	movl -8(%ebp),%eax
	movl -4(%ebp),%edx
	movl %eax,c
	movl %edx,c+4
	popl %ebx
	popl %esi
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe1:
	.size	 foo,.Lfe1-foo
	.comm	a,4,4
	.comm	b,8,4
	.comm	c,8,4
	.ident	"GCC: (GNU) 2.95.3 20010315 (release)"
#8 lore raw
Quoted 17 lines · Andrew Morton
Quoted 8 lines · Linus Torvalds
Quoted 1 line · Andrew Morton

2.95.3 and 3.2.1 seem to do it right?

Try the "64x32->64" version. gcc didn't use to get that one right, but maybe it does now.

long a;
long long b;
long long c;

Quoted 7 lines

void foo(void)

{
	c = a * b;
}

It seems to get that wrong. At least, there are three multiplies in there. 3.2.1 is similar.

You might try it unsigned. There are issues with the signed version.

Quoted 46 lines
	.file	"t.c"
	.version	"01.01"

gcc2_compiled.:
.text
.align 4
.globl foo
.type foo,@function
foo:

	pushl %ebp
	movl %esp,%ebp
	subl $16,%esp
	pushl %esi
	pushl %ebx
	movl a,%eax
	movl %eax,%ebx
	movl %eax,%esi
	sarl $31,%esi
	movl %ebx,%eax
	mull b
	movl %eax,-8(%ebp)
	movl %edx,-4(%ebp)
	movl %ebx,%eax
	imull b+4,%eax
	addl %eax,%edx
	movl %edx,-4(%ebp)
	movl b,%eax
	imull %esi,%eax
	addl %eax,-4(%ebp)
	movl -8(%ebp),%eax
	movl -4(%ebp),%edx
	movl %eax,c
	movl %edx,c+4
	popl %ebx
	popl %esi
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe1:
	.size	 foo,.Lfe1-foo
	.comm	a,4,4
	.comm	b,8,4
	.comm	c,8,4
	.ident	"GCC: (GNU) 2.95.3 20010315 (release)"
Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
#9 lore raw
In reply to Andrew Morton
Quoted 2 lines · Andrew Morton

2.95.3 and 3.2.1 seem to do it right?

Well, they do, but your test case is wrong:

Quoted 7 lines

long a;
long b;
long long c;

void foo(void)

{
	c = a * b;

This is just a 32*32->32 multiply, with a final sign extension to 64 bits.

You need to do

	c = (long long) a * b;

to get a 32*32->64 multiply. And yes, gcc gets that case right.

Linus

#13 lore raw
In reply to Linus Torvalds
Quoted 11 lines · Linus Torvalds
Quoted 2 lines · Andrew Morton

gcc will generate 64bit * 64bit multiplies without resorting to any library code

However, gcc is unable to do-the-right-thing and generate 32x32->64 multiplies, or 32x64->64 multiplies, even though those are both a _lot_ faster than the full 64x64->64 case.

And in quite a _lot_ of cases, that's actually what you want. It might actually make sense to add a "do_mul()" thing to allow architectures to do these cases right, since gcc doesn't.

Some architectures have a bit stricter limitations -- S390 limits divisor to 2^31-1, for example.

A number of systems simply flaunt the task, and instead implement mere 32/32 division in do_div().
(arm, cris, m68knommu, sh (?), sparc(32), v850)

The original pure C code to do 64/32 division to 64/32 results is very much gone in favour of architecture specific assembly codes (where system isn't 64 bit one already..)
Ah, include/asm-parisc/div64.h still has it in 2.5.64 sources..

Quoted 1 line
Quoted 1 line

and you can probably do the division with do_div().

If you need arbitrary divisions at all. Filesystems for example can (in most cases) do with power-of-two divisions, e.g.: LL >> count You may, perhaps, need to pre-calculate a number of those shift-counts when mounting a filesystem.

Quoted 3 lines

Yes. This is the same issue - gcc will always promote a 64-bit divide to be _fully_ 64-bit, even if the mixed-size 64/32 -> [64,32] case is much faster and simpler. Which is why do_div() exists in the first place.

Originally it was lib/vsprintf.c's internal (and very portable) divide numerator by small base, produce changed numerator, and remainder... The innermost element in arbitrary base number printing.

In 2.5 there is some odd: #define sector_div(a, b) do_div(a, b)
(only with CONFIG_LDB), and usage in jiffie-to-clock conversion... ... and all over the code in various odd nooks, XFS filesystem included...

Quoted 1 line

Linus

/Matti Aarnio

#10 lore raw
In reply to Andrew Morton
Quoted 6 lines · Andrew Morton
Quoted 3 lines

However, gcc is unable to do-the-right-thing and generate 32x32->64 multiplies, or 32x64->64 multiplies, even though those are both a _lot_ faster than the full 64x64->64 case.

2.95.3 and 3.2.1 seem to do it right?

Quoted 8 lines

long a;
long b;
long long c;

void foo(void)

{
	c = a * b;
}

Your code is wrong for this test. It does a 32x32->32 multiply, and then sign extends the result to 64 bits.

The correct test has "c = (long long) a * b;".

-- Jamie

#14 lore raw
In reply to Linus Torvalds

Ok, here is what I have. I changed nano sleep to use a local 64-bit value for the target expire time in jiffies. As much as MAX-INT/2-1 will be put in the timer at any one time. It loops till the target time is met or exceeded. The changes affect (clock)nanosleep only and not timers (they still error out for large values).

I now use the simple u64=(long long) a * b for the mpy so I have dropped the sc_math.h stuff (I will bring that round again :).

What do you think?

Oh, the code passes the tests I have, but I have not tried to test for very large sleep times.
-g

Quoted 29 lines · Linus Torvalds
Quoted 2 lines · Felipe Alfaro Solana

why not sleep(0)?

I think a much more likely (and correct) usage for big sleep values is more something like this:

	do_with_timeout(xxx, int timeout)
	{
		struct timespec ts;

		... set up some async event ..
		ts.tv_nsec = 0;
		ts.tv_sec = timeout;
		while (nanosleep(&ts, &ts)) {
			if (async event happened)
				return happy;
		}
		.. tear down the async event if it didn't happen ..
	}

and here the natural thing to do in user space is to just make the "no timeout" case be a huge value.

At which point it is a _bug_ in the kernel if we return early with some random error code.

Linus

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
include/linux/thread_info.h +1 -1
diff -urP -I '\$Id:.*Exp \$' -X /usr/src/patch.exclude linux-2.5.64-kb/include/linux/thread_info.h linux/include/linux/thread_info.h
@@ -12,7 +12,7 @@
  */
 struct restart_block {
 	long (*fn)(struct restart_block *);
-	unsigned long arg0, arg1, arg2;
+	unsigned long arg0, arg1, arg2, arg3;
 };
 
 extern long do_no_restart_syscall(struct restart_block *parm);
kernel/posix-timers.c +44 -37

147 lines not on this page · raw message

#15 lore raw
Quoted 6 lines · george anzinger

Ok, here is what I have. I changed nano sleep to use a local 64-bit value for the target expire time in jiffies. As much as MAX-INT/2-1 will be put in the timer at any one time. It loops till the target time is met or exceeded. The changes affect (clock)nanosleep only and not timers (they still error out for large values).

Seem sane.

Quoted 2 lines

I now use the simple u64=(long long) a * b for the mpy so I have dropped the sc_math.h stuff (I will bring that round again :).

Resistance shall be unflagging!

Quoted 1 line

What do you think?

Sorry, but this little bit:

	while ((active = del_timer_sync(&new_timer) || 
		rq_time > get_jiffies_64()) &&

!test_thread_flag(TIF_SIGPENDING));

if (abs_struct.list.next) {
spin_lock_irq(&nanosleep_abs_list_lock); list_del(&abs_struct.list); spin_unlock_irq(&nanosleep_abs_list_lock);
}
if (active) {

should be dragged out and mercifully shot. Is it possible to make that while loop a little clearer?

The abs_list exactly duplicates the kernel's existing waitqueue functionality. You can use prepare_to_wait()/finish_wait() there.

posix_timers_id, posix_clocks[], nanosleep_abs_list_lock and nanosleep_abs_list should be static to posix-timers.c.

#16 lore raw
Quoted 35 lines · Andrew Morton
Quoted 5 lines · george anzinger

Ok, here is what I have. I changed nano sleep to use a local 64-bit value for the target expire time in jiffies. As much as MAX-INT/2-1 will be put in the timer at any one time. It loops till the target time is met or exceeded. The changes affect (clock)nanosleep only and not timers (they still error out for large values).

Seem sane.

Quoted 1 line

I now use the simple u64=(long long) a * b for the mpy so I have dropped the sc_math.h stuff (I will bring that round again :).

Resistance shall be unflagging!

Quoted 1 line

What do you think?

Sorry, but this little bit:

	while ((active = del_timer_sync(&new_timer) || 
		rq_time > get_jiffies_64()) &&
(quoted diff) +0 -0
 	       !test_thread_flag(TIF_SIGPENDING));
 
 
 	if (abs_struct.list.next) {
 		spin_lock_irq(&nanosleep_abs_list_lock);
 		list_del(&abs_struct.list);
 		spin_unlock_irq(&nanosleep_abs_list_lock);
 	}
 	if (active) {
Quoted 2 lines

should be dragged out and mercifully shot. Is it possible to make that while loop a little clearer?

I hung it! It was less of a mess to clean up :)

Quoted 3 lines

The abs_list exactly duplicates the kernel's existing waitqueue functionality. You can use prepare_to_wait()/finish_wait() there.

Well, almost. Wants to mess with the state, but, try the attached.

Quoted 3 lines

posix_timers_id, posix_clocks[], nanosleep_abs_list_lock and nanosleep_abs_list should be static to posix-timers.c.

And a few more :)

Signature · 3 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
include/linux/thread_info.h +1 -1
diff -urP -I '\$Id:.*Exp \$' -X /usr/src/patch.exclude linux-2.5.64-kb/include/linux/thread_info.h linux/include/linux/thread_info.h
@@ -12,7 +12,7 @@
  */
 struct restart_block {
 	long (*fn)(struct restart_block *);
-	unsigned long arg0, arg1, arg2;
+	unsigned long arg0, arg1, arg2, arg3;
 };
 
 extern long do_no_restart_syscall(struct restart_block *parm);
kernel/posix-timers.c +56 -76

241 lines not on this page · raw message

#11 lore raw
In reply to Andrew Morton
Quoted 8 lines · Andrew Morton
Quoted 3 lines

However, gcc is unable to do-the-right-thing and generate 32x32->64 multiplies, or 32x64->64 multiplies, even though those are both a _lot_ faster than the full 64x64->64 case.

2.95.3 and 3.2.1 seem to do it right?

Quoted 7 lines

long a;
long b;
long long c;

void foo(void)

{
	c = a * b;

(long * long) is a long
(long long = long) has to sign extend right side and do assignment

Quoted 6 lines

}

	.file	"t.c"
	.version	"01.01"
Quoted 11 lines

gcc2_compiled.:
.text
.align 4
.globl foo
.type foo,@function
foo:
pushl %ebp
movl %esp,%ebp
movl a,%eax
imull b,%eax
movl %eax,c

store low word...

Quoted 1 line

cltd

sign extend eax into edx...

Quoted 1 line
	movl %edx,c+4

store sign-extended high word

In other words, you lost high 32 bits of 32x32 mul here due to error in C code.

Proper example would be c = ((long long)a) * b;
--
vda