recv return constraints

If you call recv() to fetch data, the syscall will block if nothing happens. But what are the constraints for tcp_recvmsg() to return? This posting focus on the major factors (other aspects like OOB data, signals, non-blocking IO is ignored in this posting): Timeout Amount of data tcp_recvmsg() first calculate the timeout for this function via sock_rcvtimeo(). This refers to return noblock ? 0 : sk->sk_rcvtimeo - in the common therefore sk->sk_rcvtimeo....

May 4, 2008 · 1 min · Hagen Paul Pfeifer

MSG_WAITALL and recv

The recv() function has a really rare argument: MSG_WAITALL. It tells that the syscall should not return before length bytes are read. The problem is that normally nobody knows how much data is send by the peer node. So if you rely on a particular amount of data and the data isn’t send, this call blocks infinity! On the other hand, a programmer must also handle this kind of failure, because a simple read() of a socket can also block forever....

May 2, 2008 · 2 min · Hagen Paul Pfeifer

SIMD++, SSE4 and SIMD16

The SSE4 programming reference is out - a opportunity to study the improvements. Besides 47 (plus 7 additional for the nehalem microarchitecture) new instructions which mainly focus on multimedia acceleration. MPSADBW (Sum of Absolute Differences), PHMINPOSUW Minimum Search (find minimum uint16_t from eight elements) (if you invite the source you had an fast max() ;-), ROUND (round floating point types) and other instructions too. Dot product matrix calculation, load hint instruction (MOVNTDQA) to store aligned data in a small data-set, packed integer format conversions (convert in wider data types), IEEE 754 Compliance operations....

April 26, 2008 · 1 min · Hagen Paul Pfeifer

GCC Optimization Aliasing

In talks I often noted that in the a big part, pointer casts are dump and futile. The C Standard stated out that a cast to another type raise an “undefined behavior”: float a = 23.f; uint32\_t b = \*(uint32\_t \*)&a; Depending on the current gcc version this leads to different results in b. Sometimes a is interpreted as a uint32_t type (that what you want - probably) - sometimes the result is 0;...

April 24, 2008 · 2 min · Hagen Paul Pfeifer

SIMD To Use Intrinsics Or Not To Use Intrinsics

At a high level, intrinsics is something like a different syntax for vanilla SIMD asm. For example to add two 128 bit width vectors you can use _mm_add_ps() (thats leads to a SSE instructions). The advantage of using intrinsic is that both, gcc and icc understand them. No need to #ifdef __GCC__ and other compile-time hacks. On the other side, i386 intrinsics are limited. For every SIMD extension (mmx, sse, …) you must implement a own specialized version via...

April 24, 2008 · 1 min · Hagen Paul Pfeifer

Netsend Improvements

due a productive weekend we implement three additional protocols for netsend DCCP ( RFC 4340 ) SCTP ( RFC 2960 ) UDP-LITE ( RFC 3828 ) So nowadays there are seven supported protocols (if you consider ip and transport layer protocols). TCP, IPv4, IPv6, TIPC and UDP. Some minor bugs are fixed and code rearanged - the daily work …

April 1, 2008 · 1 min · Hagen Paul Pfeifer