Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp306040imm; Tue, 16 Oct 2018 23:53:11 -0700 (PDT) X-Google-Smtp-Source: ACcGV61rdmdk0t92/lYvKsRxIlbZ9n/PadZVC+6iL9WujXZAD2EPHz+c8qwKojcL+W4ULcx+xsjh X-Received: by 2002:a63:565d:: with SMTP id g29-v6mr22970282pgm.227.1539759191758; Tue, 16 Oct 2018 23:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539759191; cv=none; d=google.com; s=arc-20160816; b=PfJ3pmX5/m+yEn8G7qrsUoZQcjCfs1/Vs2Q+614jef7zd/I3+hCNvDqpmW2SSEbK77 agKTcI3cPQMYCpaE5OE6Os2EvDTCC6KKmjV5hcKOyFPDM8zFXVPJhuOpjOIwBrmO/r9A 8A73Lm72JHhP3P+sJFWVOaVOhyJjpU3JSRs+8ClzuqYrdltA6ogCNt6Iw9nYKMwwAgq7 GeWjAEDbrj0Hy4JigLpagzY7o7LT6UgC8YXOiCuO7inxJIQvJ5OjmOaLruRwLz/G6Om9 QrQEWJdN6DwkibS+wHSC3VOHMwF66F0UKJ4icHY7pQLNqyyUWYEjhXa24nnuRTFP2M2U KHuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date; bh=U33ZsPOWDYzi9WIJG2RpeAybE9TnP+mTtkQJh+B8Lz8=; b=o1gFQHhvRmgCquyAQVe5hRUBe9Z3rLwFXPhz6y2I50pgfwJ3cG255YBhGb8nlLxi5K WFJu44CTZQTKHcAfV5yMw3vW2ngMOKnctdgwbMsHMeCaPZ/faiFUE8lQIFiFSe+eLk1z /9wzAVHn5+JtwgysJ01ZNlqiRsrxlN9eSqW4FdgickGZu6+Qcoywrc0hC8ByIcMkw/ED P2aSB2TwiMGOdld6aVAB6cFI+tDPjjFf4epQYBsUNlf8nk2VMhqaXnv7/9eq6fTYh5RJ 3DjGctv89lCt+wL+HgGYdYm6IgiJ2pvU1h0Al9xfLstYDpnEIZZEiWu+e605HTFsg5Be qKWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 29-v6si16793055pgl.104.2018.10.16.23.52.56; Tue, 16 Oct 2018 23:53:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727708AbeJQOqM (ORCPT + 99 others); Wed, 17 Oct 2018 10:46:12 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53612 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727460AbeJQOqM (ORCPT ); Wed, 17 Oct 2018 10:46:12 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9H6n1NV063109 for ; Wed, 17 Oct 2018 02:52:00 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2n5x40nn43-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 17 Oct 2018 02:51:59 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 17 Oct 2018 07:51:57 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 17 Oct 2018 07:51:50 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w9H6pnJx18087996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 17 Oct 2018 06:51:50 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D7E514C046; Wed, 17 Oct 2018 06:51:49 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 14C444C040; Wed, 17 Oct 2018 06:51:46 +0000 (GMT) Received: from linux.vnet.ibm.com (unknown [9.126.150.29]) by d06av22.portsmouth.uk.ibm.com (Postfix) with SMTP; Wed, 17 Oct 2018 06:51:45 +0000 (GMT) Date: Wed, 17 Oct 2018 12:21:45 +0530 From: Srikar Dronamraju To: Mathieu Desnoyers Cc: Peter Zijlstra , "Paul E . McKenney" , Boqun Feng , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Thomas Gleixner , Andy Lutomirski , Dave Watson , Paul Turner , Andrew Morton , Russell King , Ingo Molnar , "H . Peter Anvin" , Andi Kleen , Chris Lameter , Ben Maurer , Steven Rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon , Michael Kerrisk , Joel Fernandes Subject: Re: [RFC PATCH for 4.21 03/16] sched: Implement push_task_to_cpu (v2) Reply-To: Srikar Dronamraju References: <20181010191936.7495-1-mathieu.desnoyers@efficios.com> <20181010191936.7495-4-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20181010191936.7495-4-mathieu.desnoyers@efficios.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-TM-AS-GCONF: 00 x-cbid: 18101706-0028-0000-0000-00000308889F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18101706-0029-0000-0000-000023C39939 Message-Id: <20181017065145.GA7111@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-10-16_14:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810170062 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mathieu, > +int push_task_to_cpu(struct task_struct *p, unsigned int dest_cpu) > +{ In your use case, is the task going to be current? If yes, we should simply be using migrate_task_to. > + struct rq_flags rf; > + struct rq *rq; > + int ret = 0; > + > + rq = task_rq_lock(p, &rf); > + update_rq_clock(rq); > + > + if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) { > + ret = -EINVAL; > + goto out; > + } Ideally we should have checked cpus_allowed/cpu_active_mask before taking the lock. This would help reduce the contention on the rqlock when the passed parameter is not correct. > + > + if (!cpumask_test_cpu(dest_cpu, cpu_active_mask)) { > + ret = -EBUSY; > + goto out; > + } > + > + if (task_cpu(p) == dest_cpu) > + goto out; Same as above. > + > + if (task_running(rq, p) || p->state == TASK_WAKING) { Why are we using migration thread to move a task in TASK_WAKING state? > + struct migration_arg arg = { p, dest_cpu }; > + /* Need help from migration thread: drop lock and wait. */ > + task_rq_unlock(rq, p, &rf); > + stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg); > + tlb_migrate_finish(p->mm); > + return 0; Why cant we use migrate_task_to instead? > + } else if (task_on_rq_queued(p)) { > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index 455fa330de04..27ad25780204 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -1340,6 +1340,15 @@ static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu) > #endif > } > > +#ifdef CONFIG_SMP > +int push_task_to_cpu(struct task_struct *p, unsigned int dest_cpu); > +#else > +static inline int push_task_to_cpu(struct task_struct *p, unsigned int dest_cpu) > +{ > + return 0; > +} > +#endif > + Your usecase is outside kernel/sched. So I am not sure if this is the right place for the declaration.