DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 5295WqQA1809858
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 5295WqQA1809858
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=ZCTvrwn1
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 985F33858D38
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1741498370;
	bh=Ke84wKLgHSG+Jnsm3lGOU8hx+68Zrjs0ZBXdnPocNiU=;
	h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
	 From;
	b=ZCTvrwn1mjgNMMjMfU0Qs244wvYbje+/wMMOBPJLo/G0k95nFIK/7iRVLOMtb7Hla
	 ViNTmA094TiGq5i2QXtWtF4a5hqu70j+76mQjDSfM2JL6JXOzO9HYfHjqnQ3jSXJRa
	 mZk26cobyQEVDkxvcTORHGuz4vodPnE+yUVe9ICg=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C4BF3858D1E
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2C4BF3858D1E
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741498347; cv=none;
 b=f24/yLUwjGtc2BzzZ7tW75usH1DESSt70jkdVB5orzroc3y3kQKSYGl/L+2WxVOaMRINJOV+bpIXfECdeTbWIP7znCM1HHthvP63mv9gQ2tSTKPthxUyEz8FUeTi1Sbp4Np67r1RCkj+YNQPA1poMEAvi1JPk1zyNrq6kb0AI+s=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1741498347; c=relaxed/simple;
 bh=zQ/MYf/zwCX6iDwUFHiKO3elByEyMLD3e3YcESNSSAw=;
 h=Message-ID:Date:MIME-Version:Subject:To:From;
 b=DUxUb24OPl4lOnwodNzEmYU8+uARfexjUf+2RzoHyFXcJ4KIst3WG4uLQiXLLF0P7xVDJr/aX4o4AfBCLKSztN8Huikxc54eVJJW+ukrPSPzYqjf365cNBlTQwL6WWQwCBvaypFrRfE/fo8fJcB3W2TObWS79dyxqPU+NRFCNlQ=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C4BF3858D1E
Message-ID: <bf6885b2-0fe9-4cfe-bbda-a6b06e8839ff@maxrnd.com>
Date: Sat, 8 Mar 2025 21:32:33 -0800
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: sched_getaffinity() always returns the full cpu mask
To: cygwin@cygwin.com
References: <378d90a0-bff5-36d1-d1f7-8a28e046af2a@t-online.de>
Content-Language: en-US
In-Reply-To: <378d90a0-bff5-36d1-d1f7-8a28e046af2a@t-online.de>
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Mark Geisert via Cygwin <cygwin@cygwin.com>
Reply-To: Mark Geisert <mark@maxrnd.com>
Content-Type: text/plain; charset="utf-8"; Format="flowed"
Errors-To: cygwin-bounces~archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 5295WqQA1809858

Hi Christian,

On 3/8/2025 9:11 AM, Christian Franke via Cygwin wrote:
> Testcase:
> 
> $ grep processor /proc/cpuinfo | tail -1 # i7-14700K
> processor       : 27
> 
> $ sleep 60 & taskset 0x1 sleep 60 &
> [1] 62094
> [2] 62095
> 
> $ taskset -p 62094
> pid 62094's current affinity mask: fffffff
> 
> $ taskset -p 62095
> pid 62095's current affinity mask: fffffff
> 
> 
> Another test shows that the affinity mask is correctly set to 0x1 by 
> sched_setaffinity().
> 
> In sched.cc:__sched_getaffinity_sys(), GetProcessAffinityMask() is 
> called, but its 'procmask' result is never used. The returned cpu_set is 
> build using groupmask(__get_cpus_per_group ()) which is constant, here 
> 0xfffffff. The original commit 641ecb07 likely worked (until 687c4bad^) 
> on older Windows versions which did not support cpu groups.
> 
> I don't know how to fix this for systems with more than one cpu group, 
> so no patch provided.
> 
> It might be needed to handle interesting corner cases: "If the process 
> had explicitly set the affinity of one or more of its threads outside of 
> the process' primary group, the function returns zero for both affinity 
> masks."
> https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase- 
> getprocessaffinitymask

Thanks very much for the report and diagnosis.  I will investigate shortly.

..mark

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

