From owner-freebsd-hackers@FreeBSD.ORG Sat Feb 15 00:00:06 2014 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EC25564A; Sat, 15 Feb 2014 00:00:06 +0000 (UTC) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 83E51149D; Sat, 15 Feb 2014 00:00:04 +0000 (UTC) Received: from porto.starpoint.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id CAA20878; Sat, 15 Feb 2014 02:00:02 +0200 (EET) (envelope-from avg@FreeBSD.org) Received: from localhost ([127.0.0.1]) by porto.starpoint.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1WESfq-000OIM-70; Sat, 15 Feb 2014 02:00:02 +0200 Message-ID: <52FEADC9.2040608@FreeBSD.org> Date: Sat, 15 Feb 2014 01:59:05 +0200 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Andrey Chernov , John Baldwin Subject: Re: can the scheduler decide to schedule an interrupted but runnable thread on another CPU core? What are the implications for code? References: <201402141318.44743.jhb@freebsd.org> <52FE5FBF.3090104@freebsd.org> <201402141410.29325.jhb@freebsd.org> <52FE93E6.6030705@freebsd.org> <52FE9A5E.5050300@freebsd.org> In-Reply-To: <52FE9A5E.5050300@freebsd.org> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: "freebsd-hackers@freebsd.org" , "freebsd-arch@freebsd.org" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Feb 2014 00:00:07 -0000 on 15/02/2014 00:36 Andrey Chernov said the following: > On 15.02.2014 2:08, Andrey Chernov wrote: >> On 14.02.2014 23:10, John Baldwin wrote: >> >>>> Due to this bug, not fixed yet, the real picture is more complex: >>>> http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/163585 >>> >>> Eh, that bug report has no useful details, as in, it doesn't list the >>> actual commands run. If you do 'cpuset -l 6 -s 1' to force all >>> processes to only use CPU6, then yes, of course the other CPUs are idle >>> because that's what you _asked_ for. AFAICT, that is all the original >>> reporter did. At work we regularly add and remove CPUs from the >>> default set (set 1) on hundreds of machines every day with ULE without >>> any issues. >> >> Probably original report lack certain commands, but I provide the link >> to the port which reproduces this bug too. All threads there are >> assigned to the _different_ CPUs and appears as result on single one >> with SCHED_ULE (not with SCHED_4BSD). And it is what original reporter >> mean too. It surely happens, maybe not the first time, but on 2nd-3rd. >> It means that cpuset_setaffinity() is completely broken form SCHED_ULE >> at least for 3 years. >> > > This is code example from cpuminer port, in case you are interested, it is very simple: > > static inline void affine_to_cpu(int id, int cpu) > { > cpuset_t set; > CPU_ZERO(&set); > CPU_SET(cpu, &set); > cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_CPUSET, -1, sizeof(cpuset_t), &set); I think that CPU_WHICH_TID should have been used here. > } > ... > num_processors = sysconf(_SC_NPROCESSORS_CONF); > if (!opt_n_threads) > opt_n_threads = num_processors; > ... > In the thread itself: > struct thr_info *mythr = userdata; > int thr_id = mythr->id; > > if (num_processors > 1 && opt_n_threads % num_processors == 0) { > if (!opt_quiet) > applog(LOG_INFO, "Binding thread %d to cpu %d", > thr_id, thr_id % num_processors); > affine_to_cpu(thr_id, thr_id % num_processors); > } > -- Andriy Gapon