Re: Memory barriers & the kernel
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=t4Hs8oAzzG20WKuJzhQQhwbvFJ0zrZJRrwAGWSqrWEY=; b=U2ycZP/ef3bJdNRKOXKRJyZ4STpPMqAFbrgOOTx3Agm65whiyzbdQnT0Ub96kLKqgk sHYBeAKbscPgN6Dk46hr3TrL+cg8aEH2WdWjZ24QU8nLcHGntDAubcPrxFa+TsUZwq+3 iZ32dbgHx77yioGXaeGymo1/edtRkvSdfvrHQ= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=k+ioX8U9Z0cvUZ8XUZWKwox9HjNekeYshkfWL+4/BkLwtknoH35hWxpvuPgx/Yv6Ha JW9nf4pHZFB22li2WObNqaRqV1pCJC39dLFRK8MAB4dnPih5Eo+aubJ0GijltZu/xHAo AOiZIjaPYbJNeuqmuHYXuPoYbE6zq/ch5DJoY= After further digging, I believe I've found the answers to my questions. I'm documenting my findings here for the sake of the archives. 1. The kernel's mutex facilities do indeed include memory barriers (at least the one I've looked at anyway - lck_mtx_t.) The implementation of lck_mtx_lock() can be seen here: http://opensource.apple.com/source/xnu/xnu-1456.1.26/osfmk/i386/i386_lock.s The core mechanism is the lock/cmpxchg instruction. As stated by Intel's 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A, section 8.1.2.2 (http://www.intel.com/Assets/PDF/manual/253668.pdf): "Locked instructions can be used to synchronize data written by one processor and read by another processor. For the P6 family processors, locked operations serialize all outstanding load and store operations (that is, wait for them to complete)." 2. The OSAtomic functions in kernel-space also include a barrier, which is mentioned in the 10.6 version of OSAtomic.h. (I was reading the 10.5 header in my original email.) The kernel-space atomic functions are defined here: http://opensource.apple.com/source/xnu/xnu-1456.1.26/libkern/i386/OSAtomic.s Note the lock/cmpxchgl CAS instructions. Furthermore, I found that both the barrier and non-barrier OSAtomic functions in user-space actually both use a barrier. The user-space atomic functions are defined here: http://opensource.apple.com/source/Libc/Libc-583/i386/sys/OSAtomic.s (Note the DECLARE macro at the beginning, which is the mechanism for combining the barrier and non-barrier versions of the various atomic functions.) This file references functions in the commpage: http://opensource.apple.com/source/xnu/xnu-1456.1.26/osfmk/i386/commpage/ato... ... and once again we find our lock/cmpxchgl. _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com
participants (1)
-
Dave Keck