From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 14 22:36:24 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 DB65E7CF for ; Fri, 14 Feb 2014 22:36:23 +0000 (UTC) Received: from mail-ee0-f52.google.com (mail-ee0-f52.google.com [74.125.83.52]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 67B391DBB for ; Fri, 14 Feb 2014 22:36:23 +0000 (UTC) Received: by mail-ee0-f52.google.com with SMTP id e53so5966302eek.39 for ; Fri, 14 Feb 2014 14:36:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=x8xxOQBDIs7K3LPirTh/iZf1+TrjzpM+a/QZiY5ZdHk=; b=U0FPXCgayTaxqvbEKO2047YlEIS+J8K/Q+Mo8q+cxLFOacnX+CJ3jN3LbcFIgcCOdr D3pY8zMiDTUDO7DAwMBJDG93BE4nJ2RAv+p6voXB6Wg1xYHeHUzA/r0e/uj1nKmpTef4 e5kpFFoQlEx9ZDEkJlCHtaN04iEwSmv3ihZnKYX/HNJDutg1PD+6iTQ0PqQtXM5NPgcQ 3nUGGVYlSTyp3B1K1to+t1FgGpWe/MjDAfjk7J4BnSWHNHrfgAxcEMqBgok5nwADsZVV /ZgLrxo2JIA90ADrVujyf6A5yNXWeFa+5rA0VL1s3osR3uUXWIL8VxdmVxgSijlaXjCL fxfA== X-Gm-Message-State: ALoCoQm3ZZNOC0VHFq6lyheDNEDVAEHgdLwAftvL7or3RF8FiMKJ/UUSltIElZoBmpeEj3XOOtjN X-Received: by 10.14.87.129 with SMTP id y1mr12051788eee.38.1392417375195; Fri, 14 Feb 2014 14:36:15 -0800 (PST) Received: from [192.168.1.2] ([89.169.173.68]) by mx.google.com with ESMTPSA id 46sm24812320ees.4.2014.02.14.14.36.14 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Feb 2014 14:36:14 -0800 (PST) Message-ID: <52FE9A5E.5050300@freebsd.org> Date: Sat, 15 Feb 2014 02:36:14 +0400 From: Andrey Chernov User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: 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> In-Reply-To: <52FE93E6.6030705@freebsd.org> X-Enigmail-Version: 1.7a1pre Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 7bit Cc: "freebsd-hackers@freebsd.org" , Adrian Chadd , Ryan Stone , "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: Fri, 14 Feb 2014 22:36:24 -0000 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); } ... 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); } -- http://ache.vniz.net/