delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/10/15/09:04:29

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA238385828D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1697375066;
bh=VziYmFFrD1qsl9c0l4hLRjKYCJMA1rolFLlW27RBgJs=;
h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=QWHxnC0FRL8Dv2PlRLN/il2uZ0iKdwqUrqsVnvP2QZpoPjpgMcic1a4ue+UrPvsdy
RA6jLNh5xvZ16U+0OdD4e0Dq4W9a0DtnmxuCaaN+soF5m+tfBEpOy/iOVnur4/XF29
HeuSstTzUHzk+tR/Vymgz/f05YLIHmPiAsAZYhow=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E545D3858D33
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697375053; cv=none;
b=Hw0ad7BMSLCBVseDH28jwAZo+F7HRFvx4WnvsRiL/S42JTHqgd6xCzf5fM5OvGj65LpadT7ogEnA5SD9XL1bR0Rg6X8nfhJX6Whz5gN/aNMz2KjqseNYDzoU8uxDh3poeJc3wWWWWK8zpLxvli9ZPQ/89LMoRAxjBxGFoMSlPDw=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1697375053; c=relaxed/simple;
bh=PhbdCzcCXadGNvMjp11URvkgiUnSiAd9YV4POCHHKOM=;
h=Subject:To:From:Message-ID:Date:MIME-Version;
b=RWvkYEAlYimzG0k9epn6onymkZGvda0JZydberRTsaLoP3cccdOVWY4Amsj+DaHPfPSpZNBdvA/XSNoFKE1sFU30OetP9yKb56+xjoetLiQBQY6QtJcGkzLo7iHDeVQ5HwHvh6BhUjpRxzAfwm2QbYRND2H5WWGag6EPrXJiECk=
ARC-Authentication-Results: i=1; server2.sourceware.org
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E545D3858D33
Subject: Re: Run a Cygwin process with "higher" scheduler priority
To: cygwin AT cygwin DOT com
References: <CALXu0UeiEH3gOYzwVjOqTgQ1OC8z=ZBOd4y4ky_-B0t5SrS9Pg AT mail DOT gmail DOT com>
<cfbece04-40d6-566d-a4b8-f5334b1d453a AT Shaw DOT ca>
<CALXu0Ufnz-uHKJfjDj3xShJR=w_Mwx8Xiw2qbRvJbxo=yqV_Uw AT mail DOT gmail DOT com>
<6652d1ac-6ed9-824c-1bca-28ac49d01db7 AT cs DOT umass DOT edu>
<d4e2d459-59bd-4be5-a47e-aecf7863cbcb AT Shaw DOT ca>
Message-ID: <eb337eaf-40d4-5113-0629-43fcb76a8ffc@t-online.de>
Date: Sun, 15 Oct 2023 15:04:06 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
SeaMonkey/2.53.16
MIME-Version: 1.0
In-Reply-To: <d4e2d459-59bd-4be5-a47e-aecf7863cbcb@Shaw.ca>
X-TOI-EXPURGATEID: 150726::1697375046-FD3DFD6D-53B13B0D/0/0 CLEAN NORMAL
X-TOI-MSGID: 7e1dc5cb-a80f-4692-a4c5-c5a303a402fe
X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, BODY_8BITS,
FREEMAIL_FROM, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE,
RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Christian Franke via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Christian Franke <Christian DOT Franke AT t-online DOT de>
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 39FD4TRQ002369

Brian Inglis via Cygwin wrote:
> On 2023-10-14 07:47, Eliot Moss via Cygwin wrote:
>> On 10/14/2023 7:39 AM, Cedric Blancher via Cygwin wrote:
>>> On Fri, 11 Aug 2023 at 19:14, Brian Inglis wrote:
>>>> ...
>>>
>>>> ...
>>>> $ cygcheck -p usr/bin/chrt
>>>> Found 2 matches for usr/bin/chrt
>>>> util-linux-debuginfo-2.33.1-2 - util-linux-debuginfo: Debug info 
>>>> for util-linux
>>>> util-linux-2.33.1-2 - util-linux: Collection of basic system utilities
>>>> $ cygcheck -p usr/bin/taskset
>>>> Found 2 matches for usr/bin/taskset
>>>> util-linux-debuginfo-2.33.1-2 - util-linux-debuginfo: Debug info 
>>>> for util-linux
>>>> util-linux-2.33.1-2 - util-linux: Collection of basic system utilities
>>>> so you may need to install util-linux (coreutils is already 
>>>> installed as a base
>>>> package for Cygwin) then:
>>>>          $ man nice renice taskset chrt
>>> chrt does not work, the syscalls for realtime seem to be not 
>>> implemented.

These are partly implemented, but sched_setscheduler() always fails with 
ENOSYS because scheduler policy (SCHED_*) cannot be changed on Windows. 
Changing priority only with sched_setparam() would work, but this is not 
used by chrt.


>>>> You may need to run these from an elevated admin shell for other 
>>>> user ids,
>>>> unowned processes, or higher (negative) priority.
>>>> It has been years since I tried these so can no longer remember if -20
>>>> corresponds to Windows "RealTime" or if you need to use PowerShell 
>>>> to set that e.g.
>>>>          $proc   = Get-Process -ProcessName "..."
>>>>          $proc.PriorityClass     = "RealTime"
>>>> and that needs to be done from an elevated admin (Power)Shell.
>>>> Of course, never set that on any system except on a very idle, very 
>>>> I/O bound,
>>>> well tested process, such as ntpd, that needs stably fast interrupt 
>>>> service and
>>>> non-preemptible cpu access for ms every few seconds, preferably on 
>>>> a single or
>>>> few cpus to which affinity is set.
>>> Is there anything in /proc which can tell me the current *Windows*
>>> scheduler priority level? Or a command line tool?
>> I recall getting taskset going in util-linux a while back, but I don't
>> recall working on priority related things.  You could look into the
>> cygwin source code to see how Windows priorities relate to the priority
>> values in Cygwin.  Then you may be able just to use /proc/[pid]/stat
>> read out what you want.
>
> ISTR testing nice/renice, and found it was a simple priority mapping 
> to/from Unix to Windows Idle to RealTime (at the time, process 
> Affinity was not supported, so went with a PowerShell startup script 
> instead); see:
>
> https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/sched.cc#l107 
>
>
> https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/sched.cc#l234 
>
>
> https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/sched.cc#l277 
>

The above maps priorities for sched_*() API. The mapping for nice() and 
get/setpriority() is done here:

https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/miscfuncs.cc;h=767384f#l110


> They are documented in proc(5) /proc/PID/stat fields 18 priority and 
> 19 nice typically 20 and 0, as shown by `top` PR and NI, shown by 
> `procps -l` as 80 and 0, and not shown by Cygwin `ps`.

On Cygwin, field 18 is always equal to (field_19 + 20). The priority 
value returned by sched_getparam() is different and could be shown with 
'chrt -p PID'.

The output from the command 'nice' without parameter may differ from 
/proc/PID/stat field 19 because the latter always reinterprets the 
current Windows prio class.

This script prints a table of 'nice' outputs, /proc/PID/stat fields 19 
and 18, result of sched_getparam() and corresponding Windows prio class 
for different 'nice -n ...' commands:

#!/bin/bash
echo "COMMAND    : NICE  STAT STPRI RTPRI  WINPRI"
for i in {-21..20}; do
   nice -n $i sh -e -c '
     n=$(nice)
     s=$(cut -d" " -f19 /proc/$$/stat)
     p=$(cut -d" " -f18 /proc/$$/stat)
     r=$(LC_MESSAGES=C chrt -p $$ | sed -n "s,^.*priority: ,,p")
     case $r in
       3)  c="IDLE_PRIORITY_CLASS" ;;
       9)  c="BELOW_NORMAL_PRIORITY_CLASS" ;;
       15) c="NORMAL_PRIORITY_CLASS" ;;
       21) c="ABOVE_NORMAL_PRIORITY_CLASS" ;;
       27) c="HIGH_PRIORITY_CLASS" ;;
       32) c="REALTIME_PRIORITY_CLASS" ;;
       *)  c="?" ;;
     esac
     printf "nice -n %3d:%5d %5d %5d %5d  %s\\n" \
            "'$i'" "$n" "$s" "$p" "$r" "$c"
   '
done

-- 
Regards,
Christian


-- 
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019