Re: gnu asm help...
On 19 Jun 01 at 13:21, Richard B. Johnson wrote: > On Tue, 19 Jun 2001, Timur Tabi wrote: > > Oh, I see the problem. You could do something like this: > > > > cli > > mov %0, %%eax > > inc %%eax > > mov %%eax, %0 > > sti > > > > and then return eax, but that won't work on SMP (whereas the "lock inc" does). > > Doing a global cli might work, though. Use spinlocks instead of global cli. Global cli can take milliseconds. > The Intel book(s) state that an interrupt is not acknowledged until > so many clocks (don't remember the number) after a stack operation. Reread it. It says 'after operation with ss' - that is after "mov ,%ss" or "pop %ss", as it is expected that next instruction will be "movl ,%esp". Before "lss " (it is lss in intel mnemonic...) was invented, you could not switch your stack safely without this feature, as NMI could arrive in the middle of your stack switch without blocking all interrupts after "mov ,%ss". BTW, if you chain "mov %eax,%ss" back to back, they are executed in pairs - irq can arrive after even mov, but cannot after odd (at least on PII and PIII). But it is a bit off topic for L-K (except that we can try other clones, maybe someone got it wrong?) Best regards, Petr Vandrovec [EMAIL PROTECTED] - 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/
Re: gnu asm help...
On Tue, 19 Jun 2001, Timur Tabi wrote: > ** Reply to message from "Petr Vandrovec" <[EMAIL PROTECTED]> on Tue, 19 Jun > 2001 01:36:26 MET-1 > > > > No. Another CPU might increment value between LOCK INCL and > > fetching v->counter. On ia32 architecture you are almost out of > > luck. You can either try building atomic_inc around CMPXCHG, > > using it as conditional store (but CMPXCHG is not available > > on i386), or you can just guard your atomic variable with > > spinlock - but in that case there is no reason for using atomic_t > > at all. > > Oh, I see the problem. You could do something like this: > > cli > mov %0, %%eax > inc %%eax > mov %%eax, %0 > sti > > and then return eax, but that won't work on SMP (whereas the "lock inc" does). > Doing a global cli might work, though. The Intel book(s) state that an interrupt is not acknowledged until so many clocks (don't remember the number) after a stack operation. Given this, is an 'attack' by another CPU allowed within this time-frame? If not, you can do: pushl %ebx movlINPUT_VALUE(%esp), %eax # Get input value movlINPUT_PTR(%esp), %ebx # Get input pointer lock addl%eax,(%ebx) # Add value pushl (%ebx) # Put result on stack popl%eax# Return value in EAX popl%ebx It may be worth an experiment. In any event, you can always use a local lock to make these operations atomic. # Stack offsets VALUE = 0x08 POINTER = 0x0C .section .data __local_lock: .long 0 .section .text .global add_atom .type add_atom,@function add_atom: pushf cli incb(__local_lock) # Set the lock 1: cmpb$1,(__local_lock) jnz 1b pushl %ebx movlVALUE(%esp), %eax movlPOINTER(%esp), %ebx addl%eax, (%ebx) movl(%ebx), %eax popl%ebx decb(__local_lock) # Release the lock popf ret The lock can also be done as: incb(__local_lock) 1: cmpb$1,(__local_lock) jz 2f repz nop jmp 1b 2: (maybe) the CPU being locked loops in low-power mode. Cheers, Dick Johnson Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips). "Memory is like gasoline. You use it up when you are running. Of course you get it all back when you reboot..."; Actual explanation obtained from the Micro$oft help desk. - 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/
Re: gnu asm help...
** Reply to message from "Petr Vandrovec" <[EMAIL PROTECTED]> on Tue, 19 Jun 2001 01:36:26 MET-1 > No. Another CPU might increment value between LOCK INCL and > fetching v->counter. On ia32 architecture you are almost out of > luck. You can either try building atomic_inc around CMPXCHG, > using it as conditional store (but CMPXCHG is not available > on i386), or you can just guard your atomic variable with > spinlock - but in that case there is no reason for using atomic_t > at all. Oh, I see the problem. You could do something like this: cli mov %0, %%eax inc %%eax mov %%eax, %0 sti and then return eax, but that won't work on SMP (whereas the "lock inc" does). Doing a global cli might work, though. -- Timur Tabi - [EMAIL PROTECTED] Interactive Silicon - http://www.interactivesi.com - 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/
Re: gnu asm help...
> I need a simple (??) change to atomic_inc() functionality. so that i can > increment and return the value of the variable. Please don't blindly change atomic.h to do this. A large number of processors don't have the x86 'xadd' functionality. Create/use seperate functions instead - 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/
Re: gnu asm help...
On Tue, Jun 19, 2001 at 01:18:41AM +0200, Erik Mouw wrote: > I also don't know the exact meaning, but here are two nice tutorials > about inline assembly: > > http://www-106.ibm.com/developerworks/linux/library/l-ia.html > http://www.uwsg.indiana.edu/hypermail/linux/kernel/9804.2/0953.html this one is nice too: http://www.delorie.com/gnu/docs/gcc/gcc_86.html -- wbr - 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/
Re: gnu asm help...
On Tue, Jun 19, 2001 at 01:18:41AM +0200, Erik Mouw wrote: I also don't know the exact meaning, but here are two nice tutorials about inline assembly: http://www-106.ibm.com/developerworks/linux/library/l-ia.html http://www.uwsg.indiana.edu/hypermail/linux/kernel/9804.2/0953.html this one is nice too: http://www.delorie.com/gnu/docs/gcc/gcc_86.html -- wbr - 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/
Re: gnu asm help...
** Reply to message from Petr Vandrovec [EMAIL PROTECTED] on Tue, 19 Jun 2001 01:36:26 MET-1 No. Another CPU might increment value between LOCK INCL and fetching v-counter. On ia32 architecture you are almost out of luck. You can either try building atomic_inc around CMPXCHG, using it as conditional store (but CMPXCHG is not available on i386), or you can just guard your atomic variable with spinlock - but in that case there is no reason for using atomic_t at all. Oh, I see the problem. You could do something like this: cli mov %0, %%eax inc %%eax mov %%eax, %0 sti and then return eax, but that won't work on SMP (whereas the lock inc does). Doing a global cli might work, though. -- Timur Tabi - [EMAIL PROTECTED] Interactive Silicon - http://www.interactivesi.com - 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/
Re: gnu asm help...
On Tue, 19 Jun 2001, Timur Tabi wrote: ** Reply to message from Petr Vandrovec [EMAIL PROTECTED] on Tue, 19 Jun 2001 01:36:26 MET-1 No. Another CPU might increment value between LOCK INCL and fetching v-counter. On ia32 architecture you are almost out of luck. You can either try building atomic_inc around CMPXCHG, using it as conditional store (but CMPXCHG is not available on i386), or you can just guard your atomic variable with spinlock - but in that case there is no reason for using atomic_t at all. Oh, I see the problem. You could do something like this: cli mov %0, %%eax inc %%eax mov %%eax, %0 sti and then return eax, but that won't work on SMP (whereas the lock inc does). Doing a global cli might work, though. The Intel book(s) state that an interrupt is not acknowledged until so many clocks (don't remember the number) after a stack operation. Given this, is an 'attack' by another CPU allowed within this time-frame? If not, you can do: pushl %ebx movlINPUT_VALUE(%esp), %eax # Get input value movlINPUT_PTR(%esp), %ebx # Get input pointer lock addl%eax,(%ebx) # Add value pushl (%ebx) # Put result on stack popl%eax# Return value in EAX popl%ebx It may be worth an experiment. In any event, you can always use a local lock to make these operations atomic. # Stack offsets VALUE = 0x08 POINTER = 0x0C .section .data __local_lock: .long 0 .section .text .global add_atom .type add_atom,@function add_atom: pushf cli incb(__local_lock) # Set the lock 1: cmpb$1,(__local_lock) jnz 1b pushl %ebx movlVALUE(%esp), %eax movlPOINTER(%esp), %ebx addl%eax, (%ebx) movl(%ebx), %eax popl%ebx decb(__local_lock) # Release the lock popf ret The lock can also be done as: incb(__local_lock) 1: cmpb$1,(__local_lock) jz 2f repz nop jmp 1b 2: (maybe) the CPU being locked loops in low-power mode. Cheers, Dick Johnson Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips). Memory is like gasoline. You use it up when you are running. Of course you get it all back when you reboot...; Actual explanation obtained from the Micro$oft help desk. - 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/
Re: gnu asm help...
On 19 Jun 01 at 13:21, Richard B. Johnson wrote: On Tue, 19 Jun 2001, Timur Tabi wrote: Oh, I see the problem. You could do something like this: cli mov %0, %%eax inc %%eax mov %%eax, %0 sti and then return eax, but that won't work on SMP (whereas the lock inc does). Doing a global cli might work, though. Use spinlocks instead of global cli. Global cli can take milliseconds. The Intel book(s) state that an interrupt is not acknowledged until so many clocks (don't remember the number) after a stack operation. Reread it. It says 'after operation with ss' - that is after mov ,%ss or pop %ss, as it is expected that next instruction will be movl ,%esp. Before lss (it is lss in intel mnemonic...) was invented, you could not switch your stack safely without this feature, as NMI could arrive in the middle of your stack switch without blocking all interrupts after mov ,%ss. BTW, if you chain mov %eax,%ss back to back, they are executed in pairs - irq can arrive after even mov, but cannot after odd (at least on PII and PIII). But it is a bit off topic for L-K (except that we can try other clones, maybe someone got it wrong?) Best regards, Petr Vandrovec [EMAIL PROTECTED] - 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/
Re: gnu asm help...
I need a simple (??) change to atomic_inc() functionality. so that i can increment and return the value of the variable. Please don't blindly change atomic.h to do this. A large number of processors don't have the x86 'xadd' functionality. Create/use seperate functions instead - 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/
Re: gnu asm help...
The C-names-in-asms stuff is explained in (g?)as.info. The explanation is a bit strained, but after the third or fourth read it becomes fairly sensible. Rick Hohensee - 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/
Re: gnu asm help...
On 18 Jun 01 at 18:20, Timur Tabi wrote: > You want to return the variable? Try this: > > static __inline__ unsigned long atomic_inc(atomic_t *v) > { > __asm__ __volatile__( > LOCK "incl %0" > :"=m" (v->counter) > :"m" (v->counter)); > > return v->counter; > } No. Another CPU might increment value between LOCK INCL and fetching v->counter. On ia32 architecture you are almost out of luck. You can either try building atomic_inc around CMPXCHG, using it as conditional store (but CMPXCHG is not available on i386), or you can just guard your atomic variable with spinlock - but in that case there is no reason for using atomic_t at all. Best regards, Petr Vandrovec [EMAIL PROTECTED] P.S.: Why you need to know that value? You can either rewrite your code with atomic_dec_and_test/atomic_inc_and_test, or you overlooked some race, or you have really strange problem. - 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/
Re: gnu asm help...
** Reply to message from "Raj, Ashok" <[EMAIL PROTECTED]> on Mon, 18 Jun 2001 15:56:50 -0700 > also if there is any reference to the gnu asm symtax, please send me a > pointer.. There's lots > i can understand what the LOCK "incl %0 means.. but not sure what the rest > is for. LOCK just means the x86 "lock" prefix. incl is the 32-bit version of "inc" (incremement) You want to return the variable? Try this: static __inline__ unsigned long atomic_inc(atomic_t *v) { __asm__ __volatile__( LOCK "incl %0" :"=m" (v->counter) :"m" (v->counter)); return v->counter; } -- Timur Tabi - [EMAIL PROTECTED] Interactive Silicon - http://www.interactivesi.com - 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/
Re: gnu asm help...
On Mon, Jun 18, 2001 at 03:56:50PM -0700, Raj, Ashok wrote: > i can understand what the LOCK "incl %0 means.. but not sure what the rest > is for. > > thanks > ashokr > > static __inline__ void atomic_inc(atomic_t *v) > { > __asm__ __volatile__( > LOCK "incl %0" > :"=m" (v->counter) > :"m" (v->counter)); > } I also don't know the exact meaning, but here are two nice tutorials about inline assembly: http://www-106.ibm.com/developerworks/linux/library/l-ia.html http://www.uwsg.indiana.edu/hypermail/linux/kernel/9804.2/0953.html Erik -- J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department of Electrical Engineering, Faculty of Information Technology and Systems, Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands Phone: +31-15-2783635 Fax: +31-15-2781843 Email: [EMAIL PROTECTED] WWW: http://www-ict.its.tudelft.nl/~erik/ - 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/
gnu asm help...
Hello asm gurus.. I need a simple (??) change to atomic_inc() functionality. so that i can increment and return the value of the variable. current implementation in linux/include/asm/atomic.h does not do this job. any help would be greatly appreciated. ashokr from atomic.h also if there is any reference to the gnu asm symtax, please send me a pointer.. i can understand what the LOCK "incl %0 means.. but not sure what the rest is for. thanks ashokr static __inline__ void atomic_inc(atomic_t *v) { __asm__ __volatile__( LOCK "incl %0" :"=m" (v->counter) :"m" (v->counter)); } - 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/
gnu asm help...
Hello asm gurus.. I need a simple (??) change to atomic_inc() functionality. so that i can increment and return the value of the variable. current implementation in linux/include/asm/atomic.h does not do this job. any help would be greatly appreciated. ashokr from atomic.h also if there is any reference to the gnu asm symtax, please send me a pointer.. i can understand what the LOCK incl %0 means.. but not sure what the rest is for. thanks ashokr static __inline__ void atomic_inc(atomic_t *v) { __asm__ __volatile__( LOCK incl %0 :=m (v-counter) :m (v-counter)); } - 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/
Re: gnu asm help...
On Mon, Jun 18, 2001 at 03:56:50PM -0700, Raj, Ashok wrote: i can understand what the LOCK incl %0 means.. but not sure what the rest is for. thanks ashokr static __inline__ void atomic_inc(atomic_t *v) { __asm__ __volatile__( LOCK incl %0 :=m (v-counter) :m (v-counter)); } I also don't know the exact meaning, but here are two nice tutorials about inline assembly: http://www-106.ibm.com/developerworks/linux/library/l-ia.html http://www.uwsg.indiana.edu/hypermail/linux/kernel/9804.2/0953.html Erik -- J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department of Electrical Engineering, Faculty of Information Technology and Systems, Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands Phone: +31-15-2783635 Fax: +31-15-2781843 Email: [EMAIL PROTECTED] WWW: http://www-ict.its.tudelft.nl/~erik/ - 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/
Re: gnu asm help...
** Reply to message from Raj, Ashok [EMAIL PROTECTED] on Mon, 18 Jun 2001 15:56:50 -0700 also if there is any reference to the gnu asm symtax, please send me a pointer.. There's lots i can understand what the LOCK incl %0 means.. but not sure what the rest is for. LOCK just means the x86 lock prefix. incl is the 32-bit version of inc (incremement) You want to return the variable? Try this: static __inline__ unsigned long atomic_inc(atomic_t *v) { __asm__ __volatile__( LOCK incl %0 :=m (v-counter) :m (v-counter)); return v-counter; } -- Timur Tabi - [EMAIL PROTECTED] Interactive Silicon - http://www.interactivesi.com - 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/
Re: gnu asm help...
On 18 Jun 01 at 18:20, Timur Tabi wrote: You want to return the variable? Try this: static __inline__ unsigned long atomic_inc(atomic_t *v) { __asm__ __volatile__( LOCK incl %0 :=m (v-counter) :m (v-counter)); return v-counter; } No. Another CPU might increment value between LOCK INCL and fetching v-counter. On ia32 architecture you are almost out of luck. You can either try building atomic_inc around CMPXCHG, using it as conditional store (but CMPXCHG is not available on i386), or you can just guard your atomic variable with spinlock - but in that case there is no reason for using atomic_t at all. Best regards, Petr Vandrovec [EMAIL PROTECTED] P.S.: Why you need to know that value? You can either rewrite your code with atomic_dec_and_test/atomic_inc_and_test, or you overlooked some race, or you have really strange problem. - 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/
Re: gnu asm help...
The C-names-in-asms stuff is explained in (g?)as.info. The explanation is a bit strained, but after the third or fourth read it becomes fairly sensible. Rick Hohensee - 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/