Qiuyang Wu | 2 Mar 22:10 2009

pread/pwrite bug on linux (RHEL)?

Hi All,

Are there any known bugs with pread/pwrite on RHEL Linux when the disk partition is close to full?

Reduced a complex application fatal down to a simple program just opens a regular file and performs 1M
sequential pwrite() of size 8KB blocks; at every 100th write, does a pread() to load the very first 8KB
block and validate its content still matching what was originally written.

What I observed are the following when running on different machines and writing/reading to a disk
partition nearly full with slightly more than 1GB of free space according to 'df' (the program is the only
process accessing the disk) -

* Linux 2.6.9-55.ELsmp #1 SMP Fri Apr 20 16:36:54 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux  (RHEL4)

BEHAVIOR: pwrite() works for many iterations, then pread() suddenly returns data of the requested size
but filled with 0's, and strerror shows errno="No such file or directory", condition
      if(size_to_read != pread(fd, buf, size_to_read, ...)) ...
is not triggered and application has to check errno immediately after every call to pread.

CONCLUSION: serious bug, why does pread() return the expected size filled with 0? and why doesn't pwrite()
fail earlier so application has a chance to bail out and stop pushing more data to the file?

* Linux 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:14 EST 2007 x86_64 x86_64 x86_64 GNU/Linux (RHEL5)

BEHAVIOR: pwrite() works for much fewer iterations, then pread() errors out again with errno="No such
file or directory", and condition (size_to_read!=pread(...)) is asserted at the meantime, which is
slightly better but application still very hard to recover.

CONCLUSION: Bug, still, pwrite() should error out earlier if not enough space to commit data, instead of
(Continue reading)

Srinivas G. | 3 Mar 15:33 2009

RE: Assembler errors in optimization level 3 (-O3) - gcc (4.1.2)

> asm
> (
> 	"next:\n\t"
> #ifdef __x86_64__
> 	"pop %rax\n\t"
> 	"pop %rcx"
> #else
> 	"popl %eax\n\t"
> 	"popl %ecx"
> #endif
> );
> asm
> (
> 	"xorl %eax, %eax\n\t"
> 	"cpuid\n\t"
> 	"cmpl $4, %eax\n\t" 	// check if cpuid supports leaf 4
> 	"jl .single_core\n\t"	// Single core
> 	"movl $4, %eax\n\t"
> 	"movl $0, %ecx\n\t"	// start with index = 0; Leaf 4 reports
> );					// at least one valid cache
> asm
> (
> 	"cpuid"
> 	: "=a" (Regeax)
> 	:
> 	: "%ebx", "%ecx", "%edx"
> );
> asm
(Continue reading)

H.J. Lu | 10 Mar 20:25 2009

The Linux binutils is released

This is the beta release of binutils for Linux, which is
based on binutils 2009 0310 in CVS on sourceware.org plus various
changes. It is purely for Linux.

All relevant patches in patches have been applied to the source tree.
You can take a look at patches/README to see what have been applied and
in what order they have been applied.

Starting from the release, the x86 assembler no longer

	fnstsw %eax

fnstsw stores 16bit into %ax and the upper 16bit of %eax is unchanged.
Please use

	fnstsw %ax

Starting from the release, the default output section LMA
(load memory address) has changed for allocatable sections from being
equal to VMA (virtual memory address), to keeping the difference between
LMA and VMA the same as the previous output section in the same region.


.data.init_task : { *(.data.init_task) }

LMA of .data.init_task section is equal to its VMA with the old linker.
With the new linker, it depends on the previous output section. You
can use
(Continue reading)

Srinivas G. | 17 Mar 13:56 2009

Non Portable pthread (-np) API for thread creation in suspend mode

Dear All,

I have implemented a threading program using the pthread library on CentOS - 5.2 Linux system. (The CentOS
is an Enterprise Linux distribution based on the freely available sources from Red Hat Enterprise
Linux.) However, I need to create a pthread that is initially suspended. But, I did not find any API in the
pthread library which does the my requirement. So, I googled and found some of the FreeBSD thread API which
is as follows.


pthread_attr_setcreatesuspend_np  - prepare attribute for creation of suspended thread. I have also
seen that the "_np" stands for "non portable" API. (The functions with the pthread_ prefix and _np suffix
are not portable extensions to POSIX threads.)

My question is, how can I use the "_np" API on my Linux box. I guess, the "_np" API is available in "libthr"
shared library. So, I tried to download the "libthr" shared library, but there is no luck to me. 

I have also one more question, Shall I use the "libthr" shared library on my CENTOS without affecting the
"libpthread" library. If possible, please suggest me.

I can also able to implement the suspend and resume functionality with the following mechanism. But I have
also seen that with "libthr" we get better performance than "libpthread". Please look at the following
link. That is the reason, I want to use the "libthr" on my CENTOS Linux box.


static int ready_to_go = 0;
static pthread_mutex_t suspend_mutex = PTHREAD_MUTEX_INITIALIZER;
(Continue reading)

Srinivas G. | 30 Mar 19:29 2009

Is it possible to use the FreeBSD libthr.a library file on a Redhat Linux box?

Dear All,

I have written an application where I have used the libpthread library
for creating the pthreads. However, to get the maximum optimization, I
want to use the libthr.a library instead of libpthread library. However,
when I tried to use on my Redhat box, I end up with following errors.

../lib/linux/libthr.a(thr_sem.o): In function `_sem_init':
thr_sem.c:(.text+0x100): undefined reference to `ksem_init'
thr_sem.c:(.text+0x115): undefined reference to `ksem_destroy'
../lib/linux/libthr.a(thr_sem.o): In function `_sem_destroy':
thr_sem.c:(.text+0x216): undefined reference to `ksem_destroy'
../lib/linux/libthr.a(thr_sem.o): In function `_sem_timedwait':
thr_sem.c:(.text+0x2ad): undefined reference to `ksem_timedwait'
../lib/linux/libthr.a(thr_sem.o): In function `_sem_wait':

collect2: ld returned 1 exit status
make: *** [target] Error 1

I understand that the "ksem_init" is not available on the Redhat box.
Then, I have tried to use the libc.so.7 from FreeBSD. I have included
the libc.so.7 in my application to getridof the above undefined
references. Even though, I end up with the following errors.

/usr/bin/ld: errno <at>  <at> FBSD_1.0: TLS definition in /lib/libc.so.6 section 
.tbss mismatches non-TLS definition in ../lib/linux/libc.so section 
(Continue reading)