On 07/23/2010 01:02 PM, Stefan Hajnoczi wrote: >> In fact, we solve this problem through a really simple method. >> In our prototype, we removed this piece of code like this: >> void *qemu_get_ram_ptr(ram_addr_t addr) >> { >> ...... >> >> /* Move this entry to to start of the list. */ >> #ifndef CONFIG_COREMU >> /* Different core can access this function at the same time. >> * For coremu, disable this optimization to avoid data race. >> * XXX or use spin lock here if performance impact is big. */ >> if (prev) { >> prev->next = block->next; >> block->next = *prevp; >> *prevp = block; >> } >> #endif >> return block->host + (addr - block->offset); >> } >> >> CONFIG_COREMU is defined when TCG parallel mode is configured. >> And the list is more likely to be read only without hotplug device, so >> we don't use a lock to protect it. >> Reimplement this list with a lock free list is also reasonable, but >> seems unnecessary. :-) > > Ah, good :).
For this one in particular, you could just use circular lists (without a "head" node, unlike the Linux kernel's list data type, as there's always a RAM entry) and start iteration at "prev". Paolo