Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2029138rwl; Thu, 6 Apr 2023 05:04:17 -0700 (PDT) X-Google-Smtp-Source: AKy350YB2C4vKkKx36a4DZjwJExHavk5IAU44M6uJ65s690VZtrbpkKQaUR54x1hvd5EZpu4nJIz X-Received: by 2002:a17:902:e1d5:b0:19f:8bbf:9c56 with SMTP id t21-20020a170902e1d500b0019f8bbf9c56mr8988007pla.3.1680782656805; Thu, 06 Apr 2023 05:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680782656; cv=none; d=google.com; s=arc-20160816; b=uvJCXID3ALHB1tszvADnx7EDs4F5jPdKmpdt0PHowCXY0LTmO5NGyYg3vwfKkh4Sb/ +VgdK+4zDGkwUcXGP3ZNhzLcJywRgbBgtO6rA30F6oRJBToclPX1KuhLhP/T6ATYHFAv x9IMXftd+XZJ0uT61bCHTd/3TAMamWlOV4AI6fL4o0l1PRJI8+6QXU+MxX1cnykPiJP5 D0IUoD1KCbNEBJMa5UUghWROTl3K6EYBjOhSZOO64SJdCn5z3D6ygn7oYm8oRvxVTMyW xnKOw6Cg+5iFxPGXwXH0hrP5zEDGU3JviNCALvpbkHUf54EeMXaXouJO9bw9stkRvs+g UEYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=RpeUiKZblKpwqVQ8uVPclvtDcnSoPiA7m54Y8l9FAzo=; b=fndjxYl0Ds7ni/0XMA+UeTfPTn2ASlrpss9Wizdu/U4pZ4ePdd6qPSyPJH4qZPG2nP qIj6mMPIsRQ8gPjdXSy7hCPEMOjr+bfTwvNo22WsiH61ScnWq2/eqaol+2uZS0FlpvXK 7rz3zOV78RaGm9awvTTIDUPTKh/bhcO5/dffd9TBUxQQMaK6OuJjftPYjO1FAeAejPPL lDQ8HzwFX7DV53RXhM0nYnICUG+q/ZVP6sKfqtdem2nBLYcgCOJArlaV11WLrN0dBeOV ulee8k89yHJJMg9NJCl+sNcbgirhvGc97KqDUL7dSbcKaH+3dpmf8rS49eQ8JIWOjU7a vUwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JQIRqn1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a18-20020a1709027d9200b0019e6b2ed4basi1384751plm.483.2023.04.06.05.04.04; Thu, 06 Apr 2023 05:04:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JQIRqn1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbjDFMAD (ORCPT + 99 others); Thu, 6 Apr 2023 08:00:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbjDFL7e (ORCPT ); Thu, 6 Apr 2023 07:59:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25701BDD3 for ; Thu, 6 Apr 2023 04:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680782146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RpeUiKZblKpwqVQ8uVPclvtDcnSoPiA7m54Y8l9FAzo=; b=JQIRqn1munasH+gQyWIqNeb0FDaCQY3qBRv0ry0LddmkHCeyTY2qTZMx1CYVXGIB7h4Nr2 HW2Sgfmg0dTHt/csSfaFTTFOSq5nR8BQZ85P3r/tWIL7sF//JSGVc0FFJiw6Fye2H2xey+ Me1wmawzIG1kZ9P61jO9DLdlwcfJeqg= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-3-6wHZyEHhO-qbhps48e7d4g-1; Thu, 06 Apr 2023 07:55:45 -0400 X-MC-Unique: 6wHZyEHhO-qbhps48e7d4g-1 Received: by mail-qv1-f70.google.com with SMTP id m3-20020a0cbf03000000b005de7233ca79so15470389qvi.3 for ; Thu, 06 Apr 2023 04:55:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680782145; x=1683374145; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RpeUiKZblKpwqVQ8uVPclvtDcnSoPiA7m54Y8l9FAzo=; b=RAtvje2wciO4AV4tSu+PwPpWSuUJ9X6LV9FZzFyOTMO2TiuG+hB1+PlLoxB6vGzEVR Q0h5Mew/wjuBBLqoGfdO2LUWqIS3ZxFySM/8uwAL9dJIht9k8Y+q6Wf02Ar+ip8+m1eQ 0pkHBOYQEDa9kEj+Hw9hx0LsuKF2/ia1nDhF3OiIyHfUxADrLldvNkDUsKNwSOhH7vm2 7w29dcFg2DJ3D4sRF0LJ8G1edHiFytEvCFS3m4kRxg6wlf7hCd2AGSjzJYHw/or5kfGt DfxzAf0faRRKwFmJwFtOEbfvhp38qf4jFU8CsZtShqkzcA5MX5XkpmjPCrqXJz/Ls7ZZ hufQ== X-Gm-Message-State: AAQBX9d9nG9ZuOKTIfr/qgGF0RBojDq05ETIzuatCYzWIgwCInDzJrkI P0K/YWPFu28Nw1Y6pbjL3cia9ZHMgrveOblqLVZ3rj741NHpIOLTbV65XJnWAhRq2aYrGaaSegw OjyT2we2Q5t40zFqtCuPSLbd8 X-Received: by 2002:a05:6214:401c:b0:5a3:725e:425c with SMTP id kd28-20020a056214401c00b005a3725e425cmr4300041qvb.2.1680782144725; Thu, 06 Apr 2023 04:55:44 -0700 (PDT) X-Received: by 2002:a05:6214:401c:b0:5a3:725e:425c with SMTP id kd28-20020a056214401c00b005a3725e425cmr4300018qvb.2.1680782144443; Thu, 06 Apr 2023 04:55:44 -0700 (PDT) Received: from vschneid.remote.csb ([154.57.232.159]) by smtp.gmail.com with ESMTPSA id u12-20020a0ced2c000000b005dd8b934572sm466092qvq.10.2023.04.06.04.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 04:55:44 -0700 (PDT) From: Valentin Schneider To: Schspa Shi , mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com Cc: linux-kernel@vger.kernel.org, zhaohui.shi@horizon.ai, Schspa Shi Subject: Re: [PATCH v8 2/2] sched/rt: Trying to push current task when target disable migrating In-Reply-To: <20220828170303.171400-2-schspa@gmail.com> References: <20220828170303.171400-1-schspa@gmail.com> <20220828170303.171400-2-schspa@gmail.com> Date: Thu, 06 Apr 2023 12:55:41 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/08/22 01:03, Schspa Shi wrote: > When the task to push disable migration, retry to push the current > running task on this CPU away, instead doing nothing for this migrate > disabled task. > > CC: Valentin Schneider > Signed-off-by: Schspa Shi > Reviewed-by: Steven Rostedt (Google) > Reviewed-by: Dietmar Eggemann > --- > kernel/sched/core.c | 13 ++++++++++++- > kernel/sched/deadline.c | 9 +++++++++ > kernel/sched/rt.c | 8 ++++++++ > 3 files changed, 29 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index ee28253c9ac0c..056b336c29e70 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -2503,8 +2503,19 @@ int push_cpu_stop(void *arg) > if (p->sched_class->find_lock_rq) > lowest_rq = p->sched_class->find_lock_rq(p, rq); > > - if (!lowest_rq) > + if (!lowest_rq) { > + /* > + * The find_lock_rq function above could have released the rq > + * lock and allow p to schedule and be preempted again, and > + * that lowest_rq could be NULL because p now has the > + * migrate_disable flag set and not because it could not find > + * the lowest rq. So we must check task migration flag again. > + */ > + if (unlikely(is_migration_disabled(p))) > + p->migration_flags |= MDF_PUSH; > + Given p has to be on this rq initially, this implies p being migrated away to become migration_disabled() (it *can't* be scheduled while the stopper is running), in which case it's not on this rq anymore, so do we care? > goto out_unlock; > + } > > // XXX validate p is still the highest prio task > if (task_rq(p) == rq) { > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > index e7eea6cde5cb9..c8055b978dbc3 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c > @@ -2340,6 +2340,15 @@ static int push_dl_task(struct rq *rq) > */ > task = pick_next_pushable_dl_task(rq); > if (task == next_task) { > + /* > + * If next task has now disabled migrating, see if we > + * can do resched_curr(). > + */ > + if (unlikely(is_migration_disabled(task))) { > + put_task_struct(next_task); > + goto retry; > + } > + > /* > * The task is still there. We don't try > * again, some other CPU will pull it when ready. > diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c > index 57e8cd5c9c267..381ec05eb2701 100644 > --- a/kernel/sched/rt.c > +++ b/kernel/sched/rt.c > @@ -2139,6 +2139,14 @@ static int push_rt_task(struct rq *rq, bool pull) > */ > task = pick_next_pushable_task(rq); > if (task == next_task) { > + /* > + * If next task has now disabled migrating, see if we > + * can push the current task. > + */ > + if (unlikely(is_migration_disabled(task))) { > + put_task_struct(next_task); > + goto retry; > + } Similarly here, if the task has been through a switch-in / switch-out cycle, then at least for RT we'd have set_next_task_rt() `\ rt_queue_push_tasks() which will take care of it. If the task is preempted by e.g. a DL task, then the retry would fail on (next_task->prio < rq->curr->prio) and I'm thinking the same logic applies to the deadline.c. IOW, it looks like we're already doing the right thing here when the task gets scheduled out, so I don't think we need any of this. > /* > * The task hasn't migrated, and is still the next > * eligible task, but we failed to find a run-queue > -- > 2.37.2