write.2: caveats: write(2) returns zero?
Hi, The second example in the write(2) CAVEATS section is identical to the corresponding example in the read(2) page: while ((nr = write(fd, buf, sizeof(buf))) != -1 && nr != 0) read(2) returns 0 on EOF, but that logic is inapplicable to write(2). I'm not totally sure what the correct code should be but attached is my best guess. Also, if "nr" is for "Number Read", because this is the write(2) page, would "nw" be better? -- Scott Cheloha Index: lib/libc/sys/write.2 === RCS file: /cvs/src/lib/libc/sys/write.2,v retrieving revision 1.39 diff -u -p -r1.39 write.2 --- lib/libc/sys/write.25 Feb 2015 02:33:09 - 1.39 +++ lib/libc/sys/write.217 Sep 2017 03:02:57 - @@ -311,7 +311,7 @@ function call appeared in Error checks should explicitly test for \-1. Code such as .Bd -literal -offset indent -while ((nr = write(fd, buf, sizeof(buf))) > 0) +while ((nw = write(fd, buf, sizeof(buf))) > 0) .Ed .Pp is not maximally portable, as some platforms allow for @@ -325,5 +325,5 @@ and may appear as a negative number distinct from \-1. Proper loops should use .Bd -literal -offset indent -while ((nr = write(fd, buf, sizeof(buf))) != -1 && nr != 0) +while ((nw = write(fd, buf, sizeof(buf))) != -1 && nw == sizeof(buf)) .Ed
Re: no CPU frequency scaling on Purism Librem 13v2
On Sat, Sep 16, 2017 at 02:07:47PM +0200, Matthieu Herrb wrote: > On Sat, Sep 16, 2017 at 06:57:38PM +1000, Jonathan Gray wrote: > > On Sat, Sep 16, 2017 at 10:03:58AM +0200, matth...@herrb.eu wrote: > > > >Synopsis:no CPU frequency scaling on Purism Librem 13v2 > > > >Category:kern/amd64 > > > >Environment: > > > System : OpenBSD 6.2 > > > Details : OpenBSD 6.2-beta (GENERIC.MP) #0: Fri Sep 15 23:36:30 > > > CEST 2017 > > >matth...@librem.herrb.net:/usr/obj/GENERIC.MP > > > > > > Architecture: OpenBSD.amd64 > > > Machine : amd64 > > > >Description: > > > There is no hw.setperf sysctl available to control the CPU speed > > > > > > >How-To-Repeat: > > > Try to use apmd -A to save some battery life > > > >Fix: > > > unknown > > > > If vendor supplied acpi tables neglect to include _PSS in the aml you > > won't get different cpu speed states on anything more recent than > > a pentium m. > > > Hi, > > On PureOS (the Debian derivative shipped by Purism) it's the > intel_pstate driver that is used to control the CPU core speeds. > > Should I try to ask Purism to provide the proper _PSS objects in > their BIOS, or is there hope to get P states support at some point? Given there is no _PSS or _CPC the alternative seems to be MSRs. The ones related to hardware p states (HWP) available in broadwell and later. /* * Intel ACPI Component Architecture * AML/ASL+ Disassembler version 20170303 (64-bit version) * Copyright (c) 2000 - 2017 Intel Corporation * * Disassembling to symbolic ASL+ operators * * Disassembly of SSDT.3, Sat Sep 16 23:19:18 2017 * * Original Table Header: * Signature"SSDT" * Length 0x0308 (776) * Revision 0x02 * Checksum 0xEF * OEM ID "CORE " * OEM Table ID "COREBOOT" * OEM Revision 0x002A (42) * Compiler ID "CORE" * Compiler Version 0x002A (42) */ DefinitionBlock ("", "SSDT", 2, "CORE ", "COREBOOT", 0x002A) { Device (CTBL) { Name (_HID, "BOOT") // _HID: Hardware ID Name (_UID, Zero) // _UID: Unique ID Method (_STA, 0, NotSerialized) // _STA: Status { Return (0x0F) } Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings { Memory32Fixed (ReadOnly, 0x7AB8F000, // Address Base 0x8000, // Address Length ) }) } Processor (\_PR.CP00, 0x00, 0x1800, 0x06) { Name (_CST, Package (0x04) // _CST: C-States { 0x0003, Package (0x04) { ResourceTemplate () { Register (FFixedHW, 0x01, // Bit Width 0x02, // Bit Offset 0x0001, // Address 0x01, // Access Size ) }, 0x0001, 0x, 0x03E8 }, Package (0x04) { ResourceTemplate () { Register (FFixedHW, 0x01, // Bit Width 0x02, // Bit Offset 0x0010, // Address 0x01, // Access Size ) }, 0x0002, 0x004F, 0x01F4 }, Package (0x04) { ResourceTemplate () { Register (FFixedHW, 0x01, // Bit Width 0x02, // Bit Offset 0x0033, // Address 0x01, // Access Size ) }, 0x0003, 0x0097, 0x00C8 } }) } Processor (\_PR.CP01, 0x01, 0x, 0x00) { Name (_CST, Package (0x04) // _CST: C-States { 0x0003, Package (0x04) { ResourceTemplate () { Register (FFixedHW, 0x01, // Bit Width 0x02, // Bit Offset 0x0001, // Address 0x01, // Access Size ) }, 0x0001, 0x, 0x03E8 }, Package (0x04) { ResourceTemplate ()
Re: no CPU frequency scaling on Purism Librem 13v2
On Sat, Sep 16, 2017 at 06:57:38PM +1000, Jonathan Gray wrote: > On Sat, Sep 16, 2017 at 10:03:58AM +0200, matth...@herrb.eu wrote: > > >Synopsis: no CPU frequency scaling on Purism Librem 13v2 > > >Category: kern/amd64 > > >Environment: > > System : OpenBSD 6.2 > > Details : OpenBSD 6.2-beta (GENERIC.MP) #0: Fri Sep 15 23:36:30 > > CEST 2017 > > matth...@librem.herrb.net:/usr/obj/GENERIC.MP > > > > Architecture: OpenBSD.amd64 > > Machine : amd64 > > >Description: > > There is no hw.setperf sysctl available to control the CPU speed > > > > >How-To-Repeat: > > Try to use apmd -A to save some battery life > > >Fix: > > unknown > > If vendor supplied acpi tables neglect to include _PSS in the aml you > won't get different cpu speed states on anything more recent than > a pentium m. > Hi, On PureOS (the Debian derivative shipped by Purism) it's the intel_pstate driver that is used to control the CPU core speeds. Should I try to ask Purism to provide the proper _PSS objects in their BIOS, or is there hope to get P states support at some point? -- Matthieu Herrb signature.asc Description: PGP signature
Re: no CPU frequency scaling on Purism Librem 13v2
On Sat, Sep 16, 2017 at 10:03:58AM +0200, matth...@herrb.eu wrote: > >Synopsis:no CPU frequency scaling on Purism Librem 13v2 > >Category:kern/amd64 > >Environment: > System : OpenBSD 6.2 > Details : OpenBSD 6.2-beta (GENERIC.MP) #0: Fri Sep 15 23:36:30 > CEST 2017 >matth...@librem.herrb.net:/usr/obj/GENERIC.MP > > Architecture: OpenBSD.amd64 > Machine : amd64 > >Description: > There is no hw.setperf sysctl available to control the CPU speed > > >How-To-Repeat: > Try to use apmd -A to save some battery life > >Fix: > unknown If vendor supplied acpi tables neglect to include _PSS in the aml you won't get different cpu speed states on anything more recent than a pentium m. > > > sysctl hw: > > hw.machine=amd64 > hw.model=Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz > hw.ncpu=4 > hw.byteorder=1234 > hw.pagesize=4096 > hw.disknames=sd0:cab522578cd41f1b,sd1:,sd2:3e8a268bb4947e47 > hw.diskcount=3 > hw.sensors.cpu0.temp0=34.00 degC > hw.sensors.acpiac0.indicator0=On (power supply) > hw.sensors.acpibat0.volt0=7.40 VDC (voltage) > hw.sensors.acpibat0.volt1=8.35 VDC (current voltage) > hw.sensors.acpibat0.current0=unknown (rate), UNKNOWN > hw.sensors.acpibat0.amphour0=6.06 Ah (last full capacity) > hw.sensors.acpibat0.amphour1=0.91 Ah (warning capacity) > hw.sensors.acpibat0.amphour2=0.60 Ah (low capacity) > hw.sensors.acpibat0.amphour3=6.06 Ah (remaining capacity), OK > hw.sensors.acpibat0.amphour4=6.04 Ah (design capacity) > hw.sensors.acpibat0.raw0=0 (battery full), OK > hw.sensors.acpibat0.raw1=0 (discharge cycles) > hw.sensors.acpibtn0.indicator0=On (lid open) > hw.sensors.pchtemp0.temp0=34.00 degC > hw.sensors.softraid0.drive0=online (sd2), OK > hw.cpuspeed=2304 > hw.vendor=Purism > hw.product=Librem 13 v2 > hw.version=2.0 > hw.serialno=257785 > hw.physmem=17057374208 > hw.usermem=17009631232 > hw.ncpufound=4 > hw.allowpowerdown=1 > > dmesg: > OpenBSD 6.2-beta (GENERIC.MP) #0: Fri Sep 15 23:36:30 CEST 2017 > matth...@librem.herrb.net:/usr/obj/GENERIC.MP > real mem = 17057374208 (16267MB) > avail mem = 16533397504 (15767MB) > mpath0 at root > scsibus0 at mpath0: 256 targets > mainbus0 at root > bios0 at mainbus0: SMBIOS rev. 2.7 @ 0x7ab5a020 (8 entries) > bios0: vendor coreboot version "4.6-a86d1b-Purism-5" date 07/27/2017 > bios0: Purism Librem 13 v2 > acpi0 at bios0: rev 2 > acpi0: sleep states S0 S1 S2 S3 S4 S5 > acpi0: tables DSDT FACP SSDT MCFG TCPA APIC HPET > acpi0: wakeup devices XHCI(S3) PWRB(S4) > acpitimer0 at acpi0: 3579545 Hz, 24 bits > acpimcfg0 at acpi0 addr 0xe000, bus 0-255 > acpimadt0 at acpi0 addr 0xfee0: PC-AT compat > cpu0 at mainbus0: apid 0 (boot processor) > cpu0: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz, 2304.00 MHz > cpu0: > FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SENSOR,ARAT > cpu0: 256KB 64b/line 8-way L2 cache > cpu0: TSC frequency 230400 Hz > cpu0: smt 0, core 0, package 0 > mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges > cpu0: apic clock running at 24MHz > cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE > cpu1 at mainbus0: apid 1 (application processor) > cpu1: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz, 2304.00 MHz > cpu1: > FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SENSOR,ARAT > cpu1: 256KB 64b/line 8-way L2 cache > cpu1: smt 1, core 0, package 0 > cpu2 at mainbus0: apid 3 (application processor) > cpu2: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz, 2304.00 MHz > cpu2: > FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SENSOR,ARAT > cpu2: 256KB 64b/line 8-way L2 cache > cpu2: smt 1, core 1, package 0 > cpu3 at mainbus0: apid 2 (application processor) > cpu3: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz, 2304.00 MHz > cpu3: >
no CPU frequency scaling on Purism Librem 13v2
>Synopsis: no CPU frequency scaling on Purism Librem 13v2 >Category: kern/amd64 >Environment: System : OpenBSD 6.2 Details : OpenBSD 6.2-beta (GENERIC.MP) #0: Fri Sep 15 23:36:30 CEST 2017 matth...@librem.herrb.net:/usr/obj/GENERIC.MP Architecture: OpenBSD.amd64 Machine : amd64 >Description: There is no hw.setperf sysctl available to control the CPU speed >How-To-Repeat: Try to use apmd -A to save some battery life >Fix: unknown sysctl hw: hw.machine=amd64 hw.model=Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz hw.ncpu=4 hw.byteorder=1234 hw.pagesize=4096 hw.disknames=sd0:cab522578cd41f1b,sd1:,sd2:3e8a268bb4947e47 hw.diskcount=3 hw.sensors.cpu0.temp0=34.00 degC hw.sensors.acpiac0.indicator0=On (power supply) hw.sensors.acpibat0.volt0=7.40 VDC (voltage) hw.sensors.acpibat0.volt1=8.35 VDC (current voltage) hw.sensors.acpibat0.current0=unknown (rate), UNKNOWN hw.sensors.acpibat0.amphour0=6.06 Ah (last full capacity) hw.sensors.acpibat0.amphour1=0.91 Ah (warning capacity) hw.sensors.acpibat0.amphour2=0.60 Ah (low capacity) hw.sensors.acpibat0.amphour3=6.06 Ah (remaining capacity), OK hw.sensors.acpibat0.amphour4=6.04 Ah (design capacity) hw.sensors.acpibat0.raw0=0 (battery full), OK hw.sensors.acpibat0.raw1=0 (discharge cycles) hw.sensors.acpibtn0.indicator0=On (lid open) hw.sensors.pchtemp0.temp0=34.00 degC hw.sensors.softraid0.drive0=online (sd2), OK hw.cpuspeed=2304 hw.vendor=Purism hw.product=Librem 13 v2 hw.version=2.0 hw.serialno=257785 hw.physmem=17057374208 hw.usermem=17009631232 hw.ncpufound=4 hw.allowpowerdown=1 dmesg: OpenBSD 6.2-beta (GENERIC.MP) #0: Fri Sep 15 23:36:30 CEST 2017 matth...@librem.herrb.net:/usr/obj/GENERIC.MP real mem = 17057374208 (16267MB) avail mem = 16533397504 (15767MB) mpath0 at root scsibus0 at mpath0: 256 targets mainbus0 at root bios0 at mainbus0: SMBIOS rev. 2.7 @ 0x7ab5a020 (8 entries) bios0: vendor coreboot version "4.6-a86d1b-Purism-5" date 07/27/2017 bios0: Purism Librem 13 v2 acpi0 at bios0: rev 2 acpi0: sleep states S0 S1 S2 S3 S4 S5 acpi0: tables DSDT FACP SSDT MCFG TCPA APIC HPET acpi0: wakeup devices XHCI(S3) PWRB(S4) acpitimer0 at acpi0: 3579545 Hz, 24 bits acpimcfg0 at acpi0 addr 0xe000, bus 0-255 acpimadt0 at acpi0 addr 0xfee0: PC-AT compat cpu0 at mainbus0: apid 0 (boot processor) cpu0: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz, 2304.00 MHz cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SENSOR,ARAT cpu0: 256KB 64b/line 8-way L2 cache cpu0: TSC frequency 230400 Hz cpu0: smt 0, core 0, package 0 mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges cpu0: apic clock running at 24MHz cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE cpu1 at mainbus0: apid 1 (application processor) cpu1: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz, 2304.00 MHz cpu1: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SENSOR,ARAT cpu1: 256KB 64b/line 8-way L2 cache cpu1: smt 1, core 0, package 0 cpu2 at mainbus0: apid 3 (application processor) cpu2: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz, 2304.00 MHz cpu2: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SENSOR,ARAT cpu2: 256KB 64b/line 8-way L2 cache cpu2: smt 1, core 1, package 0 cpu3 at mainbus0: apid 2 (application processor) cpu3: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz, 2304.00 MHz cpu3: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,SENSOR,ARAT cpu3: 256KB 64b/line 8-way L2 cache cpu3: smt 0, core 1, package 0 ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 120 pins acpihpet0 at acpi0: 2399 Hz