)]}'
{
  "log": [
    {
      "commit": "8f17d3a5049d32392b79925c73a0cf99ce6d5af0",
      "tree": "3c2aa0cbe337684d353dd2cfb0c177b4ae15217c",
      "parents": [
        "8fdd6c6df7889dc89df3d9fe0f5bbe6733e39f48"
      ],
      "author": {
        "name": "Ingo Molnar",
        "email": "mingo@elte.hu",
        "time": "Mon Mar 27 01:16:27 2006 -0800"
      },
      "committer": {
        "name": "Linus Torvalds",
        "email": "torvalds@g5.osdl.org",
        "time": "Mon Mar 27 08:44:49 2006 -0800"
      },
      "message": "[PATCH] lightweight robust futexes updates\n\n- fix: initialize the robust list(s) to NULL in copy_process.\n\n- doc update\n\n- cleanup: rename _inuser to _inatomic\n\n- __user cleanups and other small cleanups\n\nSigned-off-by: Ingo Molnar \u003cmingo@elte.hu\u003e\nCc: Thomas Gleixner \u003ctglx@linutronix.de\u003e\nCc: Arjan van de Ven \u003carjan@infradead.org\u003e\nCc: Ulrich Drepper \u003cdrepper@redhat.com\u003e\nCc: Andi Kleen \u003cak@muc.de\u003e\nSigned-off-by: Andrew Morton \u003cakpm@osdl.org\u003e\nSigned-off-by: Linus Torvalds \u003ctorvalds@osdl.org\u003e\n"
    },
    {
      "commit": "e9056f13bfcdd054a0c3d730e4e096748d8a363a",
      "tree": "876d70d99cb679f7c4cbf6609d6341cadfb5c57e",
      "parents": [
        "62ac285f3c701f0457a15fe01baa64a965c4f5f1"
      ],
      "author": {
        "name": "Ingo Molnar",
        "email": "mingo@elte.hu",
        "time": "Mon Mar 27 01:16:21 2006 -0800"
      },
      "committer": {
        "name": "Linus Torvalds",
        "email": "torvalds@g5.osdl.org",
        "time": "Mon Mar 27 08:44:49 2006 -0800"
      },
      "message": "[PATCH] lightweight robust futexes: arch defaults\n\nThis patchset provides a new (written from scratch) implementation of robust\nfutexes, called \"lightweight robust futexes\".  We believe this new\nimplementation is faster and simpler than the vma-based robust futex solutions\npresented before, and we\u0027d like this patchset to be adopted in the upstream\nkernel.  This is version 1 of the patchset.\n\n  Background\n  ----------\n\nWhat are robust futexes?  To answer that, we first need to understand what\nfutexes are: normal futexes are special types of locks that in the\nnoncontended case can be acquired/released from userspace without having to\nenter the kernel.\n\nA futex is in essence a user-space address, e.g.  a 32-bit lock variable\nfield.  If userspace notices contention (the lock is already owned and someone\nelse wants to grab it too) then the lock is marked with a value that says\n\"there\u0027s a waiter pending\", and the sys_futex(FUTEX_WAIT) syscall is used to\nwait for the other guy to release it.  The kernel creates a \u0027futex queue\u0027\ninternally, so that it can later on match up the waiter with the waker -\nwithout them having to know about each other.  When the owner thread releases\nthe futex, it notices (via the variable value) that there were waiter(s)\npending, and does the sys_futex(FUTEX_WAKE) syscall to wake them up.  Once all\nwaiters have taken and released the lock, the futex is again back to\n\u0027uncontended\u0027 state, and there\u0027s no in-kernel state associated with it.  The\nkernel completely forgets that there ever was a futex at that address.  This\nmethod makes futexes very lightweight and scalable.\n\n\"Robustness\" is about dealing with crashes while holding a lock: if a process\nexits prematurely while holding a pthread_mutex_t lock that is also shared\nwith some other process (e.g.  yum segfaults while holding a pthread_mutex_t,\nor yum is kill -9-ed), then waiters for that lock need to be notified that the\nlast owner of the lock exited in some irregular way.\n\nTo solve such types of problems, \"robust mutex\" userspace APIs were created:\npthread_mutex_lock() returns an error value if the owner exits prematurely -\nand the new owner can decide whether the data protected by the lock can be\nrecovered safely.\n\nThere is a big conceptual problem with futex based mutexes though: it is the\nkernel that destroys the owner task (e.g.  due to a SEGFAULT), but the kernel\ncannot help with the cleanup: if there is no \u0027futex queue\u0027 (and in most cases\nthere is none, futexes being fast lightweight locks) then the kernel has no\ninformation to clean up after the held lock!  Userspace has no chance to clean\nup after the lock either - userspace is the one that crashes, so it has no\nopportunity to clean up.  Catch-22.\n\nIn practice, when e.g.  yum is kill -9-ed (or segfaults), a system reboot is\nneeded to release that futex based lock.  This is one of the leading\nbugreports against yum.\n\nTo solve this problem, \u0027Robust Futex\u0027 patches were created and presented on\nlkml: the one written by Todd Kneisel and David Singleton is the most advanced\nat the moment.  These patches all tried to extend the futex abstraction by\nregistering futex-based locks in the kernel - and thus give the kernel a\nchance to clean up.\n\nE.g.  in David Singleton\u0027s robust-futex-6.patch, there are 3 new syscall\nvariants to sys_futex(): FUTEX_REGISTER, FUTEX_DEREGISTER and FUTEX_RECOVER.\nThe kernel attaches such robust futexes to vmas (via\nvma-\u003evm_file-\u003ef_mapping-\u003erobust_head), and at do_exit() time, all vmas are\nsearched to see whether they have a robust_head set.\n\nLots of work went into the vma-based robust-futex patch, and recently it has\nimproved significantly, but unfortunately it still has two fundamental\nproblems left:\n\n - they have quite complex locking and race scenarios.  The vma-based\n   patches had been pending for years, but they are still not completely\n   reliable.\n\n - they have to scan _every_ vma at sys_exit() time, per thread!\n\nThe second disadvantage is a real killer: pthread_exit() takes around 1\nmicrosecond on Linux, but with thousands (or tens of thousands) of vmas every\npthread_exit() takes a millisecond or more, also totally destroying the CPU\u0027s\nL1 and L2 caches!\n\nThis is very much noticeable even for normal process sys_exit_group() calls:\nthe kernel has to do the vma scanning unconditionally!  (this is because the\nkernel has no knowledge about how many robust futexes there are to be cleaned\nup, because a robust futex might have been registered in another task, and the\nfutex variable might have been simply mmap()-ed into this process\u0027s address\nspace).\n\nThis huge overhead forced the creation of CONFIG_FUTEX_ROBUST, but worse than\nthat: the overhead makes robust futexes impractical for any type of generic\nLinux distribution.\n\nSo it became clear to us, something had to be done.  Last week, when Thomas\nGleixner tried to fix up the vma-based robust futex patch in the -rt tree, he\nfound a handful of new races and we were talking about it and were analyzing\nthe situation.  At that point a fundamentally different solution occured to\nme.  This patchset (written in the past couple of days) implements that new\nsolution.  Be warned though - the patchset does things we normally dont do in\nLinux, so some might find the approach disturbing.  Parental advice\nrecommended ;-)\n\n  New approach to robust futexes\n  ------------------------------\n\nAt the heart of this new approach there is a per-thread private list of robust\nlocks that userspace is holding (maintained by glibc) - which userspace list\nis registered with the kernel via a new syscall [this registration happens at\nmost once per thread lifetime].  At do_exit() time, the kernel checks this\nuser-space list: are there any robust futex locks to be cleaned up?\n\nIn the common case, at do_exit() time, there is no list registered, so the\ncost of robust futexes is just a simple current-\u003erobust_list !\u003d NULL\ncomparison.  If the thread has registered a list, then normally the list is\nempty.  If the thread/process crashed or terminated in some incorrect way then\nthe list might be non-empty: in this case the kernel carefully walks the list\n[not trusting it], and marks all locks that are owned by this thread with the\nFUTEX_OWNER_DEAD bit, and wakes up one waiter (if any).\n\nThe list is guaranteed to be private and per-thread, so it\u0027s lockless.  There\nis one race possible though: since adding to and removing from the list is\ndone after the futex is acquired by glibc, there is a few instructions window\nfor the thread (or process) to die there, leaving the futex hung.  To protect\nagainst this possibility, userspace (glibc) also maintains a simple per-thread\n\u0027list_op_pending\u0027 field, to allow the kernel to clean up if the thread dies\nafter acquiring the lock, but just before it could have added itself to the\nlist.  Glibc sets this list_op_pending field before it tries to acquire the\nfutex, and clears it after the list-add (or list-remove) has finished.\n\nThat\u0027s all that is needed - all the rest of robust-futex cleanup is done in\nuserspace [just like with the previous patches].\n\nUlrich Drepper has implemented the necessary glibc support for this new\nmechanism, which fully enables robust mutexes.  (Ulrich plans to commit these\nchanges to glibc-HEAD later today.)\n\nKey differences of this userspace-list based approach, compared to the vma\nbased method:\n\n - it\u0027s much, much faster: at thread exit time, there\u0027s no need to loop\n   over every vma (!), which the VM-based method has to do.  Only a very\n   simple \u0027is the list empty\u0027 op is done.\n\n - no VM changes are needed - \u0027struct address_space\u0027 is left alone.\n\n - no registration of individual locks is needed: robust mutexes dont need\n   any extra per-lock syscalls.  Robust mutexes thus become a very lightweight\n   primitive - so they dont force the application designer to do a hard choice\n   between performance and robustness - robust mutexes are just as fast.\n\n - no per-lock kernel allocation happens.\n\n - no resource limits are needed.\n\n - no kernel-space recovery call (FUTEX_RECOVER) is needed.\n\n - the implementation and the locking is \"obvious\", and there are no\n   interactions with the VM.\n\n  Performance\n  -----------\n\nI have benchmarked the time needed for the kernel to process a list of 1\nmillion (!) held locks, using the new method [on a 2GHz CPU]:\n\n - with FUTEX_WAIT set [contended mutex]: 130 msecs\n - without FUTEX_WAIT set [uncontended mutex]: 30 msecs\n\nI have also measured an approach where glibc does the lock notification [which\nit currently does for !pshared robust mutexes], and that took 256 msecs -\nclearly slower, due to the 1 million FUTEX_WAKE syscalls userspace had to do.\n\n(1 million held locks are unheard of - we expect at most a handful of locks to\nbe held at a time.  Nevertheless it\u0027s nice to know that this approach scales\nnicely.)\n\n  Implementation details\n  ----------------------\n\nThe patch adds two new syscalls: one to register the userspace list, and one\nto query the registered list pointer:\n\n asmlinkage long\n sys_set_robust_list(struct robust_list_head __user *head,\n                     size_t len);\n\n asmlinkage long\n sys_get_robust_list(int pid, struct robust_list_head __user **head_ptr,\n                     size_t __user *len_ptr);\n\nList registration is very fast: the pointer is simply stored in\ncurrent-\u003erobust_list.  [Note that in the future, if robust futexes become\nwidespread, we could extend sys_clone() to register a robust-list head for new\nthreads, without the need of another syscall.]\n\nSo there is virtually zero overhead for tasks not using robust futexes, and\neven for robust futex users, there is only one extra syscall per thread\nlifetime, and the cleanup operation, if it happens, is fast and\nstraightforward.  The kernel doesnt have any internal distinction between\nrobust and normal futexes.\n\nIf a futex is found to be held at exit time, the kernel sets the highest bit\nof the futex word:\n\n\t#define FUTEX_OWNER_DIED        0x40000000\n\nand wakes up the next futex waiter (if any). User-space does the rest of\nthe cleanup.\n\nOtherwise, robust futexes are acquired by glibc by putting the TID into the\nfutex field atomically.  Waiters set the FUTEX_WAITERS bit:\n\n\t#define FUTEX_WAITERS           0x80000000\n\nand the remaining bits are for the TID.\n\n  Testing, architecture support\n  -----------------------------\n\nI\u0027ve tested the new syscalls on x86 and x86_64, and have made sure the parsing\nof the userspace list is robust [ ;-) ] even if the list is deliberately\ncorrupted.\n\ni386 and x86_64 syscalls are wired up at the moment, and Ulrich has tested the\nnew glibc code (on x86_64 and i386), and it works for his robust-mutex\ntestcases.\n\nAll other architectures should build just fine too - but they wont have the\nnew syscalls yet.\n\nArchitectures need to implement the new futex_atomic_cmpxchg_inuser() inline\nfunction before writing up the syscalls (that function returns -ENOSYS right\nnow).\n\nThis patch:\n\nAdd placeholder futex_atomic_cmpxchg_inuser() implementations to every\narchitecture that supports futexes.  It returns -ENOSYS.\n\nSigned-off-by: Ingo Molnar \u003cmingo@elte.hu\u003e\nSigned-off-by: Thomas Gleixner \u003ctglx@linutronix.de\u003e\nSigned-off-by: Arjan van de Ven \u003carjan@infradead.org\u003e\nAcked-by: Ulrich Drepper \u003cdrepper@redhat.com\u003e\nSigned-off-by: Andrew Morton \u003cakpm@osdl.org\u003e\nSigned-off-by: Linus Torvalds \u003ctorvalds@osdl.org\u003e\n"
    },
    {
      "commit": "5c40f7f373889930d176a515ec375b60a70b5b49",
      "tree": "718d63553f5b9b23c5883592a2fe45b84f275687",
      "parents": [
        "b0e15190ead07056ab0c3844a499ff35e66d27cc"
      ],
      "author": {
        "name": "David Howells",
        "email": "dhowells@redhat.com",
        "time": "Fri Jan 06 00:11:43 2006 -0800"
      },
      "committer": {
        "name": "Linus Torvalds",
        "email": "torvalds@g5.osdl.org",
        "time": "Fri Jan 06 08:33:33 2006 -0800"
      },
      "message": "[PATCH] FRV: Implement futex operations for FRV\n\nThe attached patch implements futex operations for the FRV architecture. The\noperations are applicable to both MMU and no-MMU modes; though the EFAULT\nhandling will be a little bit of wasted space on the latter.\n\nSigned-off-by: David Howells \u003cdhowells@redhat.com\u003e\nSigned-off-by: Andrew Morton \u003cakpm@osdl.org\u003e\nSigned-off-by: Linus Torvalds \u003ctorvalds@osdl.org\u003e\n"
    },
    {
      "commit": "676067cfeaa16f6f338e067e83ce4733b41c0b24",
      "tree": "4468541d1b970fc240c115b69d894443d3ed564c",
      "parents": [
        "c51179fb0c77ad91df5825f8f7eb670da97e137e"
      ],
      "author": {
        "name": "Paolo \u0027Blaisorblade\u0027 Giarrusso",
        "email": "blaisorblade@yahoo.it",
        "time": "Wed Sep 21 18:38:09 2005 +0200"
      },
      "committer": {
        "name": "Linus Torvalds",
        "email": "torvalds@g5.osdl.org",
        "time": "Wed Sep 21 16:16:29 2005 -0700"
      },
      "message": "[PATCH] Remove unused var from asm/futex.h\n\nAs recently done by Russell King for ARM, commit\n4732efbeb997189d9f9b04708dc26bf8613ed721 introduces a generic asm/futex.h copied\nalong most arches, which includes a \"-ENOSYS support\" to be changed if needed.\nHowever, it includes an unused var (taken from the \"real\" version) which GCC\nwarns about.\n\nRemove it from all arches having that file version (i.e. same GIT id).\n$ git-diff-tree -r HEAD\nand\n$ git-ls-tree  -r HEAD include/|grep 9feff4ce1424bc390608326240be369eb13aa648\n\nmay be more interesting than looking at the patch itself, to make sure I\u0027ve\njust copied the arm header to all other archs having the original dummy version\nof this file.\n\nCc: Jakub Jelinek \u003cjakub@redhat.com\u003e\nSigned-off-by: Paolo \u0027Blaisorblade\u0027 Giarrusso \u003cblaisorblade@yahoo.it\u003e\nSigned-off-by: Linus Torvalds \u003ctorvalds@osdl.org\u003e\n"
    },
    {
      "commit": "4732efbeb997189d9f9b04708dc26bf8613ed721",
      "tree": "885308bb2b521e52e13aaa8a67c78b2ab3c18cd8",
      "parents": [
        "5b039e681b8c5f30aac9cc04385cc94be45d0823"
      ],
      "author": {
        "name": "Jakub Jelinek",
        "email": "jakub@redhat.com",
        "time": "Tue Sep 06 15:16:25 2005 -0700"
      },
      "committer": {
        "name": "Linus Torvalds",
        "email": "torvalds@g5.osdl.org",
        "time": "Wed Sep 07 16:57:17 2005 -0700"
      },
      "message": "[PATCH] FUTEX_WAKE_OP: pthread_cond_signal() speedup\n\nATM pthread_cond_signal is unnecessarily slow, because it wakes one waiter\n(which at least on UP usually means an immediate context switch to one of\nthe waiter threads).  This waiter wakes up and after a few instructions it\nattempts to acquire the cv internal lock, but that lock is still held by\nthe thread calling pthread_cond_signal.  So it goes to sleep and eventually\nthe signalling thread is scheduled in, unlocks the internal lock and wakes\nthe waiter again.\n\nNow, before 2003-09-21 NPTL was using FUTEX_REQUEUE in pthread_cond_signal\nto avoid this performance issue, but it was removed when locks were\nredesigned to the 3 state scheme (unlocked, locked uncontended, locked\ncontended).\n\nFollowing scenario shows why simply using FUTEX_REQUEUE in\npthread_cond_signal together with using lll_mutex_unlock_force in place of\nlll_mutex_unlock is not enough and probably why it has been disabled at\nthat time:\n\nThe number is value in cv-\u003e__data.__lock.\n        thr1            thr2            thr3\n0       pthread_cond_wait\n1       lll_mutex_lock (cv-\u003e__data.__lock)\n0       lll_mutex_unlock (cv-\u003e__data.__lock)\n0       lll_futex_wait (\u0026cv-\u003e__data.__futex, futexval)\n0                       pthread_cond_signal\n1                       lll_mutex_lock (cv-\u003e__data.__lock)\n1                                       pthread_cond_signal\n2                                       lll_mutex_lock (cv-\u003e__data.__lock)\n2                                         lll_futex_wait (\u0026cv-\u003e__data.__lock, 2)\n2                       lll_futex_requeue (\u0026cv-\u003e__data.__futex, 0, 1, \u0026cv-\u003e__data.__lock)\n                          # FUTEX_REQUEUE, not FUTEX_CMP_REQUEUE\n2                       lll_mutex_unlock_force (cv-\u003e__data.__lock)\n0                         cv-\u003e__data.__lock \u003d 0\n0                         lll_futex_wake (\u0026cv-\u003e__data.__lock, 1)\n1       lll_mutex_lock (cv-\u003e__data.__lock)\n0       lll_mutex_unlock (cv-\u003e__data.__lock)\n          # Here, lll_mutex_unlock doesn\u0027t know there are threads waiting\n          # on the internal cv\u0027s lock\n\nNow, I believe it is possible to use FUTEX_REQUEUE in pthread_cond_signal,\nbut it will cost us not one, but 2 extra syscalls and, what\u0027s worse, one of\nthese extra syscalls will be done for every single waiting loop in\npthread_cond_*wait.\n\nWe would need to use lll_mutex_unlock_force in pthread_cond_signal after\nrequeue and lll_mutex_cond_lock in pthread_cond_*wait after lll_futex_wait.\n\nAnother alternative is to do the unlocking pthread_cond_signal needs to do\n(the lock can\u0027t be unlocked before lll_futex_wake, as that is racy) in the\nkernel.\n\nI have implemented both variants, futex-requeue-glibc.patch is the first\none and futex-wake_op{,-glibc}.patch is the unlocking inside of the kernel.\n The kernel interface allows userland to specify how exactly an unlocking\noperation should look like (some atomic arithmetic operation with optional\nconstant argument and comparison of the previous futex value with another\nconstant).\n\nIt has been implemented just for ppc*, x86_64 and i?86, for other\narchitectures I\u0027m including just a stub header which can be used as a\nstarting point by maintainers to write support for their arches and ATM\nwill just return -ENOSYS for FUTEX_WAKE_OP.  The requeue patch has been\n(lightly) tested just on x86_64, the wake_op patch on ppc64 kernel running\n32-bit and 64-bit NPTL and x86_64 kernel running 32-bit and 64-bit NPTL.\n\nWith the following benchmark on UP x86-64 I get:\n\nfor i in nptl-orig nptl-requeue nptl-wake_op; do echo time elf/ld.so --library-path .:$i /tmp/bench; \\\nfor j in 1 2; do echo ( time elf/ld.so --library-path .:$i /tmp/bench ) 2\u003e\u00261; done; done\ntime elf/ld.so --library-path .:nptl-orig /tmp/bench\nreal 0m0.655s user 0m0.253s sys 0m0.403s\nreal 0m0.657s user 0m0.269s sys 0m0.388s\ntime elf/ld.so --library-path .:nptl-requeue /tmp/bench\nreal 0m0.496s user 0m0.225s sys 0m0.271s\nreal 0m0.531s user 0m0.242s sys 0m0.288s\ntime elf/ld.so --library-path .:nptl-wake_op /tmp/bench\nreal 0m0.380s user 0m0.176s sys 0m0.204s\nreal 0m0.382s user 0m0.175s sys 0m0.207s\n\nThe benchmark is at:\nhttp://sourceware.org/ml/libc-alpha/2005-03/txt00001.txt\nOlder futex-requeue-glibc.patch version is at:\nhttp://sourceware.org/ml/libc-alpha/2005-03/txt00002.txt\nOlder futex-wake_op-glibc.patch version is at:\nhttp://sourceware.org/ml/libc-alpha/2005-03/txt00003.txt\nWill post a new version (just x86-64 fixes so that the patch\napplies against pthread_cond_signal.S) to libc-hacker ml soon.\n\nAttached is the kernel FUTEX_WAKE_OP patch as well as a simple-minded\ntestcase that will not test the atomicity of the operation, but at least\ncheck if the threads that should have been woken up are woken up and\nwhether the arithmetic operation in the kernel gave the expected results.\n\nAcked-by: Ingo Molnar \u003cmingo@redhat.com\u003e\nCc: Ulrich Drepper \u003cdrepper@redhat.com\u003e\nCc: Jamie Lokier \u003cjamie@shareable.org\u003e\nCc: Rusty Russell \u003crusty@rustcorp.com.au\u003e\nSigned-off-by: Yoichi Yuasa \u003cyuasa@hh.iij4u.or.jp\u003e\nSigned-off-by: Andrew Morton \u003cakpm@osdl.org\u003e\nSigned-off-by: Linus Torvalds \u003ctorvalds@osdl.org\u003e\n"
    }
  ]
}
