Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3004541pxb; Tue, 24 Aug 2021 12:43:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzS147jRtrWfucd1M2+S8W+IYh3z/EfGCn2CSMdkl+mR8CmzAws9Q8JCUdaijpW5y/ZRtbZ X-Received: by 2002:a05:6e02:13e1:: with SMTP id w1mr29528235ilj.116.1629834211511; Tue, 24 Aug 2021 12:43:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629834211; cv=none; d=google.com; s=arc-20160816; b=QfCV90+VUub7NUYIHrnti0uwSIEeoY4+aeIgqoCdQu8oNbXAaK+4eVKfae6K5SyKHo Wf2j8nTg4cTikce3Vc9ETcS/J1Yy9QOgfKyDM0FYimod50YdTFMIcDR6RsyTlTE66Jjy UOGJDgqYTaVm9B4Wq/ErLXgnbB1D+QFFj1+jUeiuAr1tr5gpOCsjf/A1ZrrDCLmGBRDi GvwY5edzg941WOQKSa1n5ha5bbOkdH/de+2g1rnWRiDqxd2Wb4iAqc6xx+iMY9H9bwPP pFOOZA+iQVxEcj0VlKVcm8hhrJPqPlp8XTzubj1MCBqkX07b11roD78Pg06oqCNUvyOU IDeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=VfEPuan/zCIEg+H/ClhRQP2hu3myJiA0etgVi2UQg2A=; b=DWCgmM1wNPZDdY/jO0O2XuTpmA9aLJOlZvv9Rw8yT90HC2jBSjIt8c4VcgadGRImEx 7fsUJ/S42IK+pBSIhIv1xENc3xoDLjxtgG0OZiBdTTTpkN5qnrMmyotv7nD0RJnrSK2X oQtFVkVFKcaY7I+9Q9KyfGYr+q/k+oPTKrikVMpAScMLiH9cBZ7XlrOyPcS+sMTGPPBl nCVz4ulwf4aAqZsWIVa/QPsyGzCm8zAlKZEamZYGf4ntQ4a7weU6EgIJAn7xj/QhwNL7 ZnRSI3dJE981xtW916Np0xzDFVg/q35UdTx+PXzbALh5PsDZ18zaKpLWsWNvnp7mSgDe IGBw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s10si16992540ioo.6.2021.08.24.12.43.17; Tue, 24 Aug 2021 12:43:31 -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; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235058AbhHXTli (ORCPT + 99 others); Tue, 24 Aug 2021 15:41:38 -0400 Received: from mail-lf1-f41.google.com ([209.85.167.41]:44742 "EHLO mail-lf1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbhHXTlh (ORCPT ); Tue, 24 Aug 2021 15:41:37 -0400 Received: by mail-lf1-f41.google.com with SMTP id o10so47813032lfr.11; Tue, 24 Aug 2021 12:40:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VfEPuan/zCIEg+H/ClhRQP2hu3myJiA0etgVi2UQg2A=; b=QPervYaYegUocV0f39v4PtEqHuqB5WKhzL/K//mEdG56wgOzBuFSwaIMDk6/PjWf7a /rf84Q1GwnaMHp3O234UbQOYKz5vvQwtHkwlPCMKZ/lvInNM0mVhh7us82HlLeKclsB7 esvyfZB5NAxlIWn4DL+aKciOU9Xp9WFV0oExYspbUZG5JLsoBzqf3Rf+QOgvxwzp4w9I M33SBfAOIYlmWDWStYORbnkpboNexAkaxBRjAEUm8A2ZHnZmd7HRCVBrLbIp+d71xDVc ZWs3uLufrC29z879BkvXgbBwgjLZOltFSPSDjQdXf2iuWw0W7z3kHtdGGBEuiJLXJNbk VWeQ== X-Gm-Message-State: AOAM530aULFkJ9qbURP7WBB7OZ1gDGNXiESy+3uBobsxxZbtRKJY5te3 z2LUUEgiAOnrxpeL3NtrwAXBWK9T3/+YCAWuFJw= X-Received: by 2002:a05:6512:158e:: with SMTP id bp14mr22128013lfb.509.1629834051824; Tue, 24 Aug 2021 12:40:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Namhyung Kim Date: Tue, 24 Aug 2021 12:40:40 -0700 Message-ID: Subject: Re: [RFC PATCH v3 08/15] perf workqueue: add queue_work and flush_workqueue functions To: Riccardo Mancini Cc: Arnaldo Carvalho de Melo , Ian Rogers , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel , linux-perf-users , Alexey Bayduraev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 20, 2021 at 3:54 AM Riccardo Mancini wrote: > > This patch adds functions to queue and wait work_structs, and > related tests. > > When a new work item is added, the workqueue first checks if there > are threads to wake up. If so, it wakes it up with the given work item, > otherwise it will pick the next round-robin thread and queue the work > item to its queue. A thread which completes its queue will go to sleep. > > The round-robin mechanism is implemented through the next_worker > attibute which will point to the next worker to be chosen for queueing. > When work is assigned to that worker or when the worker goes to sleep, > the pointer is moved to the next worker in the busy_list, if any. > When a worker is woken up, it is added in the busy list just before the > next_worker, so that it will be chosen as last (it's just been assigned > a work item). Do we really need this? I think some of the complexity comes because of this. Can we simply put the works in a list in wq and workers take it out with a lock? Then the kernel will distribute the works among the threads for us. Maybe we can get rid of worker->lock too.. Thanks, Namhyung