Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1551432pxv; Fri, 16 Jul 2021 11:49:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBdoHc+r9G9alSAXrRCc6noLuII/WCBoiM95voOXPfHTdEpWX4WV/ch5hkOR6F1CuJV58w X-Received: by 2002:a05:6402:2206:: with SMTP id cq6mr16582711edb.209.1626461354582; Fri, 16 Jul 2021 11:49:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626461354; cv=none; d=google.com; s=arc-20160816; b=urEQ7ALOACytoa8nfh19KAE5zyzBFsydNLJ5bGvNuOMZNmjO1BaRctzoPHErtpsjPu 2sajgBCIiEPLUQvfDPHs7ooCEXeQaC/5HZKJlrnmeeW50NGOTAgtDyd7sTWti+VZuG6C nl0N4ViSqsXCZn085pVQ8B0oIiyy9oISfaYmZJxq7UyK5vjjjf31DeT793jy4V3Tl0zt n0++GG4HMJF+xx1v23FBOThi6BCBvCOTYABkGPt3vnutuUyaGnzAE6JeUpGEqPKPZxHK s5luzsbmf67XDVRF3s4VoX+fURM62rirO5UTE/yog+fBtItIUExNyZ8VGoPE4z8MMh8k uv+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=H+pBQszJfRlqDFcT5AL34vP285QtEH3o1QexaECMHjE=; b=POTsEZ+fVzJlhm2n62Yctk467P33ySLkRC9sPwLJxoSYhLo+VHgeGJkUGKD49Paf6F jLjau/xXqGQT7JmESf6DnF/9c93xZ7V3s253BgmTTaxqng8MhllRuMiyHI7OIC7uZmvN Fery/GKPUWmRbKnq9z1wegPUw0rNi4NycAgKRcVGiDSsy8xdZs2U0xQmdAa16ZSxvGSp lx2kcdPg1N1oP73g5XhUCGFfsTVcoownFcELIPgAK1E/VDlcrbl65hl4DmyyZzmPk+2b rh5ckvN7md21RV/rgagtoCa9mikq8IaTng5k0T47IZoccLPJp1+SWXWb2DC3h/XYuIxd Lv/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=C6DA69bq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kl9si12520631ejc.603.2021.07.16.11.48.51; Fri, 16 Jul 2021 11:49:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=C6DA69bq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232446AbhGPSul (ORCPT + 99 others); Fri, 16 Jul 2021 14:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232427AbhGPSuY (ORCPT ); Fri, 16 Jul 2021 14:50:24 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6971C061760 for ; Fri, 16 Jul 2021 11:47:28 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id b5-20020a17090a9905b029016fc06f6c5bso7577280pjp.5 for ; Fri, 16 Jul 2021 11:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posk.io; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=H+pBQszJfRlqDFcT5AL34vP285QtEH3o1QexaECMHjE=; b=C6DA69bqkyuEEQ3/+YCbmMXwlUQEL2xr8/dCAS92UBXzQIfwSujEmvMblQ9zZkfwFq y7i7pqMBykFqqMxhPBauRADJsOdFnqoOQqSeLwUgsH+7oLrF6GH35rs0ff7KBGgCrFjl +0RLeSt0GDAIMuIfhSscxggApj0IYW+zFOUbgFlEOTBMgU80KSryDUrLcPEMeXPm24BG hDz/KrYY9D5MstmykN0+L429aMS7EEh5mDNBBCywkkaOVN2edvjWANrWwXmxSlk/MEfq CefVoLCI64YKzU6182BkczRnBclrvgrIRnhrA8A+4ZWjJd7qCNZnDlRA/qD6AWzsjE7T c5pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=H+pBQszJfRlqDFcT5AL34vP285QtEH3o1QexaECMHjE=; b=X8cpM0voP4D7iWpE+EF33UdLHZ0zyHjb8sfX0/zrEXcKJfF6gh5/UfwYeEpeZknNUF lmGJAqAtbcs7LGtMCqwVjFeozJlVxbD9j/69ul2viaFbJMwHYgiyZaESO0AXdHsXTgTg G5+blI6MvgdQ/Hk16YVuCCn3WDXFhmjDdpC7s6XHb+woIMsOSwRCQE27oZfMrsQZsu3x srq+r42nN9+31Mtjf3o8HICnRhR4wuXG85a/eMkjSiKHEq7DjK0sQXfkrprS1xzHy4rE qAPOo3EUSHPTGAPuSdcUBTGpN52cYp2+SZTPROElR+4qeMIuzr+VJVeTnI4B//weI3iI Zdyw== X-Gm-Message-State: AOAM532ZY6tHz3kxoEoWpHODglUk8LFB4GHeuKrIDls82H22HRbsgNQ8 eCzNKvRf+lZCy4ADMxZucx98/Q== X-Received: by 2002:a17:90a:fd93:: with SMTP id cx19mr16879210pjb.65.1626461248258; Fri, 16 Jul 2021 11:47:28 -0700 (PDT) Received: from localhost.localdomain (23-118-52-46.lightspeed.sntcca.sbcglobal.net. [23.118.52.46]) by smtp.gmail.com with ESMTPSA id q125sm3170240pga.87.2021.07.16.11.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 11:47:27 -0700 (PDT) From: Peter Oskolkov X-Google-Original-From: Peter Oskolkov To: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Cc: Paul Turner , Ben Segall , Peter Oskolkov , Peter Oskolkov , Joel Fernandes , Andrei Vagin , Jim Newsome , Jann Horn , Thierry Delisle Subject: [RFC PATCH 0/4 v0.3] sched/UMCG Date: Fri, 16 Jul 2021 11:47:15 -0700 Message-Id: <20210716184719.269033-1-posk@google.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is another attempt at implementing UMCG, based on discussion in https://lore.kernel.org/patchwork/cover/1433967/ and https://lore.kernel.org/lkml/20210708194638.128950-1-posk@google.com/ Most of the "why" is covered here (some details are obsolete): https://lore.kernel.org/patchwork/cover/1433967/#1632328 At a high level, UMCG servers/workers provide the foundation for an M:N threading library, as described in the link above. Joel Fernandes has also once mentioned that he had a use case for a wake+bring-the-wakee-to-the-current-CPU operation, so this is now also supported via UMCG_WF_CURRENT_CPU flag (patch 3). Patch 1: add WF_CURRENT_CPU and tweak ttwu - same as last time Patch 2: add X86_64 helpers to work atomically with userspace values Patch 3: add helpers to work with single-linked lists in userspace Patch 4: implement UMCG kernel-side In this version of the patchset I used only userspace/TLS data, as suggested by Peter Zijlstra. With the exception of one issue (see patch 3 commit message) everything seems to be working great. This TLS-only approach makes the userspace code a bit more involved, so I'm not posting libumcg/selftests with this patchset to focus on the kernel side only. v0.2->v0.3 chages: - split patch 2 into two paches: atomic ops and llist ops - rework atomic ops in patch 2 to avoid "stac/clac nonsense" - make llist kernel-side operations constant time (no indefinite spinning) - make task wakeup work without spinning/retries I'm not aware of any issues with this patchset other than what's mentioned below. In short, it seems that "SMP basics": block/wake detection, worker "scheduling" by servers, etc. all work. TODO: - combine cmpxchg_user_32/64 functions into a macro in patch 2 - implement timeout handling - imlement worker preemption - more testing - manpages, docs, and similar - attach libumbc and selftest patches Peter Oskolkov (4): sched: add WF_CURRENT_CPU and externise ttwu sched/umcg: RFC: add userspace atomic helpers sched/umcg: RFC: add userspace sll helpers sched/umcg: RFC: implement UMCG syscalls arch/x86/entry/syscalls/syscall_64.tbl | 2 + include/linux/sched.h | 6 + include/linux/syscalls.h | 4 + include/uapi/asm-generic/unistd.h | 8 +- include/uapi/linux/umcg.h | 259 +++++++++++++ init/Kconfig | 10 + kernel/exit.c | 7 + kernel/sched/Makefile | 1 + kernel/sched/core.c | 20 +- kernel/sched/fair.c | 4 + kernel/sched/sched.h | 15 +- kernel/sched/umcg.c | 485 +++++++++++++++++++++++++ kernel/sched/umcg.h | 298 +++++++++++++++ kernel/sys_ni.c | 4 + 14 files changed, 1112 insertions(+), 11 deletions(-) create mode 100644 include/uapi/linux/umcg.h create mode 100644 kernel/sched/umcg.c create mode 100644 kernel/sched/umcg.h -- 2.25.1