From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 2DC80385842E for ; Tue, 5 Sep 2023 11:08:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2DC80385842E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-401d6f6b2e0so19561175e9.1 for ; Tue, 05 Sep 2023 04:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1693912090; x=1694516890; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3ub7rvkebpVxexExBxeFI57O/PuUjcvIrIogzl3Xet0=; b=aPA4OEA65eJwAJyMMenBQlNVkR0deWQEARASNs6ndAmgydVBYvN9HTZF9BiI5T+TLf imiaM4UmDbE3Ep6PjpsRr35MD2ZfJwdn+mkcPKtGpx49q5gdN7nVRM4u75FrNfUNS4kJ 2mgorQXafm9EAbza+O+RLsbQAgBy6w4+kyQkxB8RFtx+OHTIh7XVylAN8g2pWJtepWyC x2AWFMTqBTQ1zwo2jyb0TrZYzmEUvEmseYoP3okTRk95n7X5L9/2HVMnhVB+J8+hMS00 fItwAU7RnIYHUrGx28aL/EW+rM1aSBPgTo4z/XN8qI+cnKc1o4wTP58CbVCUKkFaJH06 ZeFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693912090; x=1694516890; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3ub7rvkebpVxexExBxeFI57O/PuUjcvIrIogzl3Xet0=; b=Phc27rifrxdG2V+TFm4bYbe1ErMeyMzlgLZc9WfdE8OC16Z4SGFEXIi5MBRAGlFh+I NJgpxJOOC7R7q8/nh+PCdPvoMfbbKoNSoEZNl8vEyFR51gO2LOJ+Vy0kQSNF4yGg0Zoq LXGqsWSznERuEQT+ZMbbOFGy1yu7e3vu78ESQQ4jNQ64iwdzPJ6bBDRZ+TSoZe2yKWh9 GXcf4DStbJIdSLwd1N6UMBrBrGqj1WW0aX4+EanaYdWG7X/YWWiGa7ZFd/iSfKCog8bi MiWvPOxyaJeUQn5BZCmhqezEd7gTKyZO/USnn9TmeYswHrwC8aTWuXY7fWOOeexgRMMR Vopw== X-Gm-Message-State: AOJu0YyNzXABSP+uYEX/ay5eFo+HzRzMGRi0UcDd6WSk1PUjNfF7rlQl WsxwYSZ9NphWeaeOpWlynLyKgPfagcFN72cYxhdGzQ== X-Google-Smtp-Source: AGHT+IHe6hBSA1bUBhC3qn7ln43/c4BkFJaumNylxnTK25/RtQepPjiaIVuzEw3gOQ7Zcj07RimrFQ== X-Received: by 2002:a5d:67cd:0:b0:314:314e:fdda with SMTP id n13-20020a5d67cd000000b00314314efddamr12145469wrw.23.1693912089856; Tue, 05 Sep 2023 04:08:09 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:20fc:79e4:455c:1075]) by smtp.gmail.com with ESMTPSA id f3-20020a7bc8c3000000b00401c595fcc7sm19797152wml.11.2023.09.05.04.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 04:08:09 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Johannes Kliemann Subject: [COMMITTED] ada: Support setting task affinity on QNX Date: Tue, 5 Sep 2023 13:08:08 +0200 Message-Id: <20230905110808.562636-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Johannes Kliemann QNX does not support setting the thread affinity via a POSIX API. This implementation uses QNX's native Thread_Ctl API to set the thread affinity for Ada tasks. gcc/ada/ * libgnarl/s-taprop__qnx.adb: Implement Set_Task_Affinity. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/libgnarl/s-taprop__qnx.adb | 45 ++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/gcc/ada/libgnarl/s-taprop__qnx.adb b/gcc/ada/libgnarl/s-taprop__qnx.adb index 13335ef4acd..423229854a8 100644 --- a/gcc/ada/libgnarl/s-taprop__qnx.adb +++ b/gcc/ada/libgnarl/s-taprop__qnx.adb @@ -49,6 +49,7 @@ with System.Interrupt_Management; with System.OS_Constants; with System.OS_Primitives; with System.Task_Info; +with System.Multiprocessors; with System.Soft_Links; -- We use System.Soft_Links instead of System.Tasking.Initialization @@ -1317,12 +1318,46 @@ package body System.Task_Primitives.Operations is ----------------------- procedure Set_Task_Affinity (T : ST.Task_Id) is - pragma Unreferenced (T); - + use type Multiprocessors.CPU_Range; + + function Thread_Ctl_Ext + (Pid : pid_t; + Tid : Thread_Id; + Command : Interfaces.C.unsigned; + Runmask : Interfaces.C.size_t) return Interfaces.C.int + with + Import, Convention => C, External_Name => "ThreadCtlExt"; + -- Thread_Ctl_Ext is a generic thread control function in QNX. + -- It is defined locally because in the C API its second + -- argument is a void pointer that takes different actual + -- pointer types or values depending on the command. This + -- particular instance of this function only accepts the + -- NTO_TCTL_RUNMASK command. The void * pointer in the C + -- interface is interpreted as bitmask for this command. + -- In the binding size_t is used as an integer type that + -- always has the same size as a pointer. + + NTO_TCTL_RUNMASK : constant := 4; + -- Command for Thread_Ctl. Using this command in Thread_Ctl + -- allows the caller to pass a bitmask that describes on + -- which CPU the current thread is allowed to run on. + + Pid : constant pid_t := getpid; + Result : Interfaces.C.int; + Runmask : Interfaces.C.size_t; + -- Each set bit in runmask represents a processor that the thread + -- can run on. If all bits are set to one the thread can run on any CPU. begin - -- Setting task affinity is not supported by the underlying system - - null; + if T.Common.Base_CPU = Multiprocessors.Not_A_Specific_CPU then + Runmask := Interfaces.C.size_t'Last; + else + Runmask := + Interfaces.C.size_t + (2 ** Natural (T.Common.Base_CPU - Multiprocessors.CPU'First)); + end if; + Result := + Thread_Ctl_Ext (Pid, Get_Thread_Id (T), NTO_TCTL_RUNMASK, Runmask); + pragma Assert (Result = 0); end Set_Task_Affinity; end System.Task_Primitives.Operations; -- 2.40.0