From http://www.reddit.com/r/C_Programming/comments/249cmt/resources_that_have_influenced_me_as_a_c/
http://stackoverflow.com/questions/tagged/c
The GNU C Library Reference. Also commonly available as 'info libc'. It should be read like a book. Really.
The Kernel CodingStyle, has some pretty good advice.
What every programmer should know about memory is very relevant for high-speed processing. This is the LWN article.
Kernel design patterns. Another great LWN link. I always smile a little whenever I use the container_of() macro.
Recursive Make Considered Harmful. Makes a fine beverage when mixed with Autotools.
Gnulib - the GNU Portability Library. Add in small quantities.
GNU C Language Extensions. I try to stay pretty compiler-agnostic, but there are some nifty things here. I would have never known about zero-length arrays if not for this.
Linux Device Drivers, 3rd edition.. Definitely worth reading.
The Linux Programming Interface. Likewise.
K&R Second Edition. Almost forgot this one!
GNU Screen. Nothing specific to C programming, but this utility deserves mention.
More than anything, man pages, 'info libc', reading header files, etc. Ways to look things up without first turning to Google, which often links to low signal-to-noise resources.
Apr 29, 2014
click is a Python package for creating beautiful command line interfaces
click is a Python package for creating beautiful command line interfaces in a composable way with as little amount of code as necessary. It’s the “Command Line Interface Creation Kit”.
import click
@click.command()
@click.option('--count', default=1, help='number of greetings')
@click.option('--name', prompt='Your name',
help='the person to greet', required=True)
def hello(count, name):
for x in range(count):
print('Hello %s!' % name)
if __name__ == '__main__':
hello()
python click_test.py --help
Usage: click_test.py [OPTIONS] NAME
Options:
--count=COUNT number of greetings
--help Show this message and exit.
Labels:
argparse,
command line,
python
Apr 27, 2014
The Linux Graphics Stack
The Direct Rendering Manager (DRM) is a device-independent kernel-level device driver that provides support for the Direct Rendering Infrastructure.
Direct Rendering Infrastructure (DRI) is an interface and a free software implementation inside the kernel used by the X Window System/Wayland to securely allow user applications to access the video hardware without requiring data to be passed through the display server. Its primary application is to provide hardware acceleration for the Mesa implementation of OpenGL, which is the core of the DRI OpenGL drivers. Without DRI, programs have to use the CPU while rendering (indirect rendering), which degrades overall performance. DRI has also been adapted to provide OpenGL acceleration on a framebuffer console without a display server running.
Mode setting (KMS) is a software operation that activates a display mode (screen resolution, color depth, and refresh rate) for a computer's display adapter.
Wayland is a protocol that specifies the communication between the display server (called Wayland compositor) and its clients. It was initially designed as a replacement for the X Window System. In stark contrast to the latter, Wayland clients will render without detour directly into their own buffer located in the graphics memory, through the use of EGL with some additional Wayland-specific extensions to EGL.
The display manager is to do the compositing, hence it will incorporate a big chunk of the functionality of current-day compositing window managers. It will composite those buffers to form the on-screen display of application windows. The Wayland protocol is essentially only about input handling and buffer management. The handling of the input hardware relies on evdev in Linux, and similar components in other operating systems.
EGL is an interface between Khronos rendering APIs (such as OpenGL, OpenGL ES or OpenVG) and the underlying native platform windowing system. EGL handles graphics context management, surface/buffer binding, rendering synchronization, and enables "high-performance, accelerated, mixed-mode 2D and 3D rendering using other Khronos APIs." EGL is managed by the non-profit technology consortium Khronos Group.
evdev (for event device) is a component of the Linux kernel for handling input (from keyboards, mice, joysticks, etc.) and a closely related input driver for both the X.Org Server and Wayland compositors. The kernel component is glue code which translates input events from peripheral-specific drivers into a generic structure which the input driver can easily translate into X11 events. Thus every input device with a Linux driver is compatible with the X.Org input driver, making X.Org much easier to configure.
Mesa is a collection of free and open-source libraries that implement OpenGL and several other APIs related to hardware-accelerated 3D rendering, 3D computer graphics and GPGPU.
Labels:
graphics stack,
kernel,
linux,
wayland,
X server
Apr 21, 2014
Elbrus-4S
Russia is ready to produce new processor Elbrus-4S based on own
microprocessors architecture with operations dependency analysis and
order optimization via compiler. Also they have Linux based OS with
modified 2.6.33 kernel that supports hard real-time scheduling
News
MCST News
Architecture (ru)
Elbrus OS (ru)
News
MCST News
Architecture (ru)
Elbrus OS (ru)
Labels:
arch,
microprocessor
Apr 18, 2014
Apr 14, 2014
Shared libraries and dynamic linker
cc -g -c prog.c mod1.c mod2.c mod3.c
cc -g -o prog_nolib prog.o mod1.o mod2.o mod3.o
strip(1) - discard symbols from object files.
Static lib:
ar r libdemo.a mod1.o mod2.o mod3.o
ar tv libdemo.a
# rw-rw-r-- 1000/1000 1003352 Apr 14 11:24 2014 mod1.o
# rw-rw-r-- 1000/1000 403352 Apr 14 11:24 2014 mod2.o
# rw-rw-r-- 1000/1000 43352 Apr 14 11:24 2014 mod3.o
cc -g -o prog prog.o libdemo.a
# or
cc -g -o prog prog.o -Lmylibdir -ldemo
./prog
Dinamic lib:
gcc -g -c -fPIC -Wall mod1.c mod2.c mod3.c
gcc -g -shared -o libfoo.so mod1.o mod2.o mod3.o
# or
gcc -g -fPIC -Wall mod1.c mod2.c mod3.c -shared -o libfoo.so
gcc -g -Wall -o prog prog.c libfoo.so
LD_LIBRARY_PATH=. ./prog
nm(1) - list symbols from object files
readelf(1) - displays information about ELF files
objdump(1) - display information from object files
ldd(1) - print shared library dependencies
ldconfig(1) - configure dynamic linker run-time bindings
nm mod1.o
readelf -s mod1.o
objdump --all-headers libfoo.so
readelf -d libfoo.so
Process shared libs:
cat /proc/PID/maps
Shared libs that prog required:
ldd /usr/sbin/tcpdump
# linux-vdso.so.1 => (0x00007fffe17ff000)
# libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007ff285828000)
# libpcap.so.0.8 => /usr/lib/x86_64-linux-gnu/libpcap.so.0.8 (0x00007ff2855ed000)
# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff285224000)
# libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff285020000)
# libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff284e07000)
# /lib64/ld-linux-x86-64.so.2 (0x00007ff28606f000)
Where function defined:
nm -A /usr/lib/lib*.so 2> /dev/null | grep ' crypt$'
All system shared libs:
ldconfig –p
#1768 libs found in cache `/etc/ld.so.cache'
# libzvbi.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libzvbi.so.0
# libzvbi-chains.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libzvbi-chains.so.0
# libzltext.so.0.13 (libc6,x86-64) => /usr/lib/libzltext.so.0.13
# libzlcore.so.0.13 (libc6,x86-64) => /usr/lib/libzlcore.so.0.13
# libzip.so.2 (libc6,x86-64) => /usr/lib/libzip.so.2
#...
Path: LD_LIBRARY_PATH, DT_RPATH, DT_RUNPATH, $ORIGIN
gcc -Wl,-rpath,'$ORIGIN'/lib ...
Run-time symbol resolution:
gcc -g -c -fPIC -Wall -c foo.c
gcc -g -shared -o libfoo.so foo.o
gcc -g -o prog prog.c libfoo.so
LD_LIBRARY_PATH=. ./prog
# main-xyz
Monitoring dynamic linker:
LD_DEBUG=help ./prog
LD_DEBUG=all ./prog
Labels:
c
Apr 7, 2014
Mar 26, 2014
Unix as IDE. Memmory profiling
cat /proc/meminfo
#MemTotal: 16350248 kB
#MemFree: 14502016 kB
#Buffers: 133516 kB
#Cached: 738584 kB
#..
#Mapped: 106640 kB
#Shmem: 78664 kB
#Slab: 101588 kB
#SReclaimable: 81208 kB
#SUnreclaim: 20380 kB
#KernelStack: 3000 kB
#PageTables: 18616 kB
#..
cat /proc/iomem
#00000000-00000fff : reserved
#00001000-0009d7ff : System RAM
#0009d800-0009ffff : reserved
#000a0000-000bffff : PCI Bus 0000:00
#000c0000-000c7fff : Video ROM
#...
cat /proc/pagetypeinfo
#Page block order: 9
#Pages per block: 512
#
# ...
#
#Number of blocks type Unmovable Reclaimable Movable Reserve Isolate
#Node 0, zone DMA 1 0 6 1 0
#Node 0, zone DMA32 8 32 1742 2 0
#Node 0, zone Normal 222 94 6069 2 0
cat /proc/buddyinfo
#Node 0, zone DMA 0 0 0 0 0 0 0 0 1 1 3
#Node 0, zone DMA32 1734 1323 616 162 59 32 10 13 7 3 749
#Node 0, zone Normal 2712 3081 1760 654 320 144 51 27 27 12 2728
sudo cat /proc/slabinfo
sudo slabtop
Shared Memory Segments
ipcs -m
#------ Shared Memory Segments --------
#key shmid owner perms bytes nattch status
#0x00000000 0 alex 600 393216 2 dest
#0x00000000 360449 alex 600 4194304 2 dest
#0x00000000 196610 alex 600 2097152 2 dest
#0x00000000 229379 alex 600 1048576 2 dest
ipcs -m -p
#
#------ Shared Memory Creator/Last-op PIDs --------
#shmid owner cpid lpid
#0 alex 3613 4418
#360449 alex 3993 4418
#196610 alex 3317 4418
#229379 alex 3613 4418
Labels:
memmory,
unix as ide
Mar 23, 2014
Qemu. Mips cpu virtualization
About MIPS architecture
Download initrd.gz and vmlinux-3.2.0-4-4kc-malta from http://ftp.debian.org/debian/dists/stable/main/installer-mips/current/images/malta/netboot/
On guest host:
Instructions for other archs with qemu:
https://gmplib.org/~tege/qemu.html
Download initrd.gz and vmlinux-3.2.0-4-4kc-malta from http://ftp.debian.org/debian/dists/stable/main/installer-mips/current/images/malta/netboot/
# install
qemu-system-mips -M malta -kernel vmlinux-3.2.0-4-4kc-malta -initrd initrd.gz \
-hda debian74_mips.img -append "root=/dev/sda1 console=ttyS0" -nographic
# boot
qemu-system-mips -M malta -kernel vmlinux-3.2.0-4-4kc-malta \
-hda debian74_mips.img -append "root=/dev/sda1 console=ttyS0" -nographic
On guest host:
uname -a
# Linux debianmips 3.2.0-4-4kc-malta #1 Debian 3.2.54-2 mips GNU/Linux
cat /proc/cpuinfo
# system type : MIPS Malta
# processor : 0
# cpu model : MIPS 24Kc V0.0 FPU V0.0
mips hello world (http://en.wikipedia.org/wiki/MIPS_architecture#MIPS_assembly_language):
00400640 <main>:
#include <stdio.h>
int main() {
400640: 27bdffe0 addiu sp,sp,-32
400644: afbf001c sw ra,28(sp)
400648: afbe0018 sw s8,24(sp)
40064c: 03a0f021 move s8,sp
printf("Hello world!\n");
400650: 3c020040 lui v0,0x40
400654: 24440810 addiu a0,v0,2064
400658: 0c100140 jal 400500 <puts@plt>
40065c: 00200825 move at,at
return 0;
400660: 00001021 move v0,zero
}
400664: 03c0e821 move sp,s8
400668: 8fbf001c lw ra,28(sp)
40066c: 8fbe0018 lw s8,24(sp)
400670: 27bd0020 addiu sp,sp,32
400674: 03e00008 jr ra
400678: 00200825 move at,at
40067c: 00200825 move at,at
i386 hello world:
0804840c <main>:
#include <stdio.h>
int main() {
804840c: 55 push ebp
804840d: 89 e5 mov ebp,esp
804840f: 83 e4 f0 and esp,0xfffffff0
8048412: 83 ec 10 sub esp,0x10
printf("Hello world!\n");
8048415: c7 04 24 c0 84 04 08 mov DWORD PTR [esp],0x80484c0
804841c: e8 cf fe ff ff call 80482f0 <puts@plt>
return 0;
8048421: b8 00 00 00 00 mov eax,0x0
}
8048426: c9 leave
8048427: c3 ret
8048428: 90 nop
8048429: 90 nop
804842a: 90 nop
804842b: 90 nop
804842c: 90 nop
804842d: 90 nop
804842e: 90 nop
804842f: 90 nop
x64 hello world:
00000000004004fd <main>:
#include <stdio.h>
int main() {
4004fd: 55 push rbp
4004fe: 48 89 e5 mov rbp,rsp
printf("Hello world!\n");
400501: bf a4 05 40 00 mov edi,0x4005a4
400506: e8 d5 fe ff ff call 4003e0 <puts@plt>
return 0;
40050b: b8 00 00 00 00 mov eax,0x0
}
400510: 5d pop rbp
400511: c3 ret
400512: 66 2e 0f 1f 84 00 00 nop WORD PTR cs:[rax+rax*1+0x0]
400519: 00 00 00
40051c: 0f 1f 40 00 nop DWORD PTR [rax+0x0]
Instructions for other archs with qemu:
https://gmplib.org/~tege/qemu.html
Labels:
hardware virtualization,
mips,
qemu
Mar 19, 2014
Kernel. Power management
cat /sys/module/cpuidle/parameters/off
cd /sys/devices/system/cpu/cpu0/cpuidle
cat */power
cat */usage
C-State
powertop
The cpuidle subsystem
Subscribe to:
Posts (Atom)



