What is the purpose of hweight macros in the linux kernel? - linux-kernel

I came across the hweight8/hweight16/hweight32/... macros when reading through some driver code in the kernel. I would like to understand, what these macros are for and what they are doing but unfortunately I failed to find any documentation on the topic.
The definition of the macros looks like this and can be found in
include/asm-generic/bitops/const_hweight.h
#define hweight8(w) (__builtin_constant_p(w) ? __const_hweight8(w) : __arch_hweight8(w))
#define hweight16(w) (__builtin_constant_p(w) ? __const_hweight16(w) : __arch_hweight16(w))
#define hweight32(w) (__builtin_constant_p(w) ? __const_hweight32(w) : __arch_hweight32(w))
#define hweight64(w) (__builtin_constant_p(w) ? __const_hweight64(w) : __arch_hweight64(w))

Ok, found the answer!
The hweight functions seem to be used for counting the number of bits equals 1 in a byte/word. I do not fully understand the use case but I have found this piece of code in the Linux NAND driver using it for checking if a block is erased (all bits are 1) while accepting some bits to be flipped.
Example calls:
hweight8(1) --> 1
hweight8(2) --> 1
hweight8(3) --> 2
hweight8(4) --> 1
hweight8(5) --> 2
hweight8(6) --> 2
hweight8(7) --> 3
hweight8(8) --> 1
and so on...

Related

Reading DS18b20 sensors using ESP-IDF using a ESP32 with a 26 MHx XTAL

I'm able to read DS18B20 sensors using the example code provided in this repository.
It works well using a standard Espressif ESP32-WROOM-32 (aka ESP32-DevKitC), which uses a 40 MHz XTAL.
I'm not able to run the same example using an Allnet-IOT-WLAN, which uses a 26 MHz XTAL.
I suspect that the problem is related with RMT initialization. The initialization is using:
rmt_tx.clk_div = 80;
I've tried different settings for clk_div with no luck.
Does anyone know how to use the DS18B20 sensor with ESP-IDF, using a board with a 26 MHz XTAL, instead of more standard 40 MHz one?
ESP32-WROOM-32 output (working)
I (0) cpu_start: Starting scheduler on APP CPU.
Find devices:
0 : d4000008e40d7428
1 : f8000008e3632528
Found 2 devices
Device 1502162ca5b2ee28 is not present
Temperature readings (degrees C): sample 1
0: 22.3 0 errors
1: 21.8 0 errors
Temperature readings (degrees C): sample 2
0: 22.3 0 errors
1: 21.9 0 errors
Allnet-IOT-WLAN output (not working)
I (0) cpu_start: Starting scheduler on APP CPU.
Find devices:
Found 0 devices
E (6780) owb_rmt: rx_items == 0
E (6880) owb_rmt: rx_items == 0
E (6980) owb_rmt: rx_items == 0
There are no differences in the RMT initialization using different XTAL clock frequencies.
D (2319) rmt: Rmt Tx Channel 1|Gpio 25|Sclk_Hz 80000000|Div 80|Carrier_Hz 0|Duty 35
D (2319) intr_alloc: Connected src 47 to int 13 (cpu 0)
D (2319) rmt: Rmt Rx Channel 0|Gpio 25|Sclk_Hz 80000000|Div 80|Thresold 77|Filter 30
Both use the same 80 MHx source.
I was using a wrong pinout diagram. I've tested the RMT with a more simple example and I found out that the pinout was wrong.
The DS18b20 sensors works well with a 26 MHz XTAL with the esp32-ds18b20 library.

Ghostscript 'offending input'

When searching for an occurrence of text in a PostScript file, I receive the following error:
gsapi_run_string_continue returns -21
The API documentation specifies that return codes > 0 are "Error" but doesn't describe it any more specifically. Full error console output below - error occurs twice identically, only one occurrence displayed here.
GPL Ghostscript 9.15 (2014-09-22)
Copyright (C) 2014 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Displaying DSC file C:/Users/c-toothm/Desktop/PRDFlow12_30_2014_050307/1230ouptut.ps
Displaying page 1
%%[ ProductName: GPL Ghostscript ]%%
%%[ LastPage ]%%
Extracting text using pstotext...
Ghostscript returns error code -21`
--- Begin offending input ---
evice /pop , d
initmatrix [1 0 0 1 0 0] concat colspSet`
0.00 43.32 +
0.94 0.95 +S
(XSFT2200041.img) run
EPSFILE2200041 restore
;
0 0 0 sco 5 Lw N 4950 4742 M 4800 4742 I K
0 0 0 sco 5 Lw N 4950 4752 M 4800 4752 I K
0 0 0 sco 5 Lw N 4950 4762 M 4800 476
--- End offending input ---
gsapi_run_string_continue returns -21`
[duplicate error redacted]
Our production output creates a giant .ps file every day and this error occurs in many, but not all, .ps files when searching for text. Randomly selected .ps files from the web do not throw the error, so this GS build seems OK - definitely a problem with my file.
What "offending input" is being referred to here and what can I do to address it?
I'd need to see the PostScript file to tell you exactly what is wrong, but 'evice' is not a PostScript operator and so that is likely the problem. Also, from ghostpdl/gs/psi/ierrors.h error code -21 is e_undefined which means the interpreter has encountered an undefined token, which is some confirmation that this is the problem.
This could be because the file contains a 'typo' like that (perhaps it should be setpagedevice or something), or it could be because a filter is improperly terminated, or has insufficient data, and consumes extra bytes from the input stream, chewing up your program.
You should start by using the Ghostscript executable and reproduce the error with that (you might also try the display device, to see whether the problem is related to pstotext), that will allow you to give a command line which other people can then duplicate. With that, and a copy of the offending file I can tell you exactly what's wrong, without it, not much hope.
Bear in mind that PostScript is an interpreted programming language, so its pretty much impossible to tell you what's wrong with your program without seeing the code.
FWIW you might like to try the Ghostscript txtwrite device instead of pstotext, the device doesn't rely on tinkering with the language like pstotext does. pstotext is also really old (the last release is coming up on its 11th birthday) and unsupported.....

MASM errors on Build in VS10

The attached code is a supplied source for a SaveGame cleaner.
The only thing that is not clear is the entry point, which has been set as main.
But the decompiler at [http://www.onlinedisassembler.com/odaweb/] gave something like _start.
The first codeblock is
; SaveTool V 1.13
_______________________________________________________________________________________
[true 1 false 0 NULL 0]
[FilterStrings: B$ 'Save Files', 0, '*.ess', 0
0,0,0]
*Error 6 error A2044: invalid character in file SaveCleaner.asm 12 1* SaveCleanerNextline
[UserFileFilter: 0 #50] [ChoosenFile: 0 #64]
[OFN_FILEMUSTEXIST 01000 OFN_PATHMUSTEXIST 0800 OFN_LONGNAMES 0200000
OFN_EXPLORER 080000 OFN_HIDEREADONLY 04]
[OFN_FLAGS OFN_FILEMUSTEXIST+OFN_PATHMUSTEXIST+OFN_LONGNAMES+OFN_HIDEREADONLY+OFN_EXPLORER]
[OpenFileNameStructure: len hwndFileOwner: 0 OF_hInstance: 0 FilterStrings
0 0 1 FullChoosenFile 200 ChoosenFile
80 NULL OpenFileTitle OFN_FLAGS
nFileOffsetinChoosenFile: W$ 0 nFileExtensioninChoosenFile: 0
DefaultExtension: D$ NULL
HookCustomData: NULL HookProcPtr: NULL HookTemplateName: 0 0 0 0 ]
[OpenFileTitle: 'Open .ess file' 0]
*Error 6 error A2044: invalid character in file SaveCleaner.asm 12 1 SaveCleanerNextline*
[FullChoosenFile: 0 #64] [<16 algn: 0]
__________________________________________________________________________________________
The complete codeblock is too large for posting here so it can be downloaded (right click) at [http://www.ozemail.com.au/~lmstearn/files/SaveTool-source.asm]
The config has been set correctly to compile the code but comes up with a mass of errors.
SaveCleaner.asm(142): error A2008: syntax error :
SaveCleaner.asm(156): error A2044: invalid character in file
SaveCleaner.asm(158): fatal error A1012: error count exceeds 100; stopping assembly
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\masm.targets(49,5): >error MSB3721: The command "ml.exe /c /nologo /Zi /Fo"Debug\SaveCleaner.obj" /I >"C:\masm32\lib" /I "C:\masm32\include" /I "C:\masm32\macros" /W3 /errorReport:prompt >/TaSaveCleaner.asm" exited with code 1.
What is missed in the VS setup?
It looks that your asm source is a RosASM source code and you will have no chance to compile it under MASM / Visual Studio.
RosASM is a win32 assembler that used a quite original design that let it store the source code inside the compiled executable (in a dedicated section) and many other features like an integrated IDE, integrated debugger, some powerful macros, a resource editor, a dialog editor, an original source navigation style that does not need scrolling bar, the possibility to divide the source in chapters called "titles"... Quite a surprising tool that need some practice to get comfortable with it, that I still use for asm win32 programming.
I have checked that the code assembles with RosASM, but I get neither an error nor a result as I do not have the corresponding game.
The original RosASM web site is now vanished, but there is a dedicated forum recently back online and I maintain an archive site where you can get binaries, and a lot of examples and fully functional applications (even a working NES emulator) made with RosASM that could help you to learn RosASM usage. FYI, SpASM is RosASM ancestor and BUASM was a revamping of RosASM that is unfinished.
Concerning the executable entry point, you can get it by looking at the Proc Main int the TITLE MAIN, that reads:
Proc Main:
call 'KERNEL32.HeapCreate' 0 0 0 | mov D$Heap eax
call 'Kernel32.GetModuleHandleA' 0 | mov D$hInstance eax
call 'USER32.DialogBoxParamA' eax IDD_MAINDIALOG &NULL DialogProc &NULL
call 'KERNEL32.HeapDestroy' D$Heap
call 'KERNEL32.ExitProcess' 0
EndP
HTH.

MS-DOS debug -l 0 not working

I want to write a bin file to a flash drive. I'm supposed to run:
n helloworld.bin
l 0
w 0 0 0 1
But when I run l 0 I get a File not found error. What am I doing wrong?
Two issues:
MS-DOS filenames should have a maximum of 8 letters before the dot and a maximum of 3 letters after the dot.
For this use of the l command in debug, provide no parameters. The file will always be loaded to CS:0100.
(I somehow find it worrying that my brain saved this useless information for all those years...)

Linpack sometimes starting, sometimes not, but nothing changed

I installed Linpack on a 2-Node cluster with Xeon processors. Sometimes if I start Linpack with this command:
mpiexec -np 28 -print-rank-map -f /root/machines.HOSTS ./xhpl_intel64
linpack starts and prints the output, sometimes I only see the mpi mappings printed and then nothing following. To me this seems like random behaviour because I don't change anything between the calls and as already mentioned, Linpack sometimes starts, sometimes not.
In top I can see that xhpl_intel64processes have been created and they are heavily using the CPU but when watching the traffic between the nodes, iftop is telling me that it nothing is sent.
I am using MPICH2 as MPI implementation. This is my HPL.dat:
# cat HPL.dat
HPLinpack benchmark input file
Innovative Computing Laboratory, University of Tennessee
HPL.out output file name (if any)
6 device out (6=stdout,7=stderr,file)
1 # of problems sizes (N)
10000 Ns
1 # of NBs
250 NBs
0 PMAP process mapping (0=Row-,1=Column-major)
1 # of process grids (P x Q)
2 Ps
14 Qs
16.0 threshold
1 # of panel fact
2 PFACTs (0=left, 1=Crout, 2=Right)
1 # of recursive stopping criterium
4 NBMINs (>= 1)
1 # of panels in recursion
2 NDIVs
1 # of recursive panel fact.
1 RFACTs (0=left, 1=Crout, 2=Right)
1 # of broadcast
1 BCASTs (0=1rg,1=1rM,2=2rg,3=2rM,4=Lng,5=LnM)
1 # of lookahead depth
1 DEPTHs (>=0)
2 SWAP (0=bin-exch,1=long,2=mix)
64 swapping threshold
0 L1 in (0=transposed,1=no-transposed) form
0 U in (0=transposed,1=no-transposed) form
1 Equilibration (0=no,1=yes)
8 memory alignment in double (> 0)
edit2:
I now just let the program run for a while and after 30min it tells me:
# mpiexec -np 32 -print-rank-map -f /root/machines.HOSTS ./xhpl_intel64
(node-0:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
(node-1:16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31)
Assertion failed in file ../../socksm.c at line 2577: (it_plfd->revents & 0x008) == 0
internal ABORT - process 0
APPLICATION TERMINATED WITH THE EXIT STRING: Hangup (signal 1)
Is this a mpi problem?
Do you know what type of problem this could be?
I figured out what the problem was: MPICH2 uses different random ports each time it starts and if these are blocked your application wont start up correctly.
The solution for MPICH2 is to set the environment variable MPICH_PORT_RANGE to START:END, like this:
export MPICH_PORT_RANGE=50000:51000
Best,
heinrich

Resources