I am playing around with the patchset “my” student generated during this years GSoC (the code for all projects is available from Google). In short, it gives you the possibility to query from userland, which optional kernel features are available. I have let him mostly do those features, which are not so easy to detect from userland, or where the detection could trigger an autoload of a kernel module.
I let the output speak for himself, first the output before his patchset:
kern.features.compat_freebsd7: 1
kern.features.compat_freebsd6: 1
kern.features.posix_shm: 1
And now with his patchset:
kern.features.compat_freebsd6: 1
kern.features.compat_freebsd7: 1
kern.features.ffs_snapshot: 1
kern.features.geom_label: 1
kern.features.geom_mirror: 1
kern.features.geom_part_bsd: 1
kern.features.geom_part_ebr: 1
kern.features.geom_part_ebr_compat: 1
kern.features.geom_part_mbr: 1
kern.features.geom_vol: 1
kern.features.invariant_support: 1
kern.features.kdtrace_hooks: 1
kern.features.kposix_priority_scheduling: 1
kern.features.ktrace: 1
kern.features.nfsclient: 1
kern.features.nfsserver: 1
kern.features.posix_shm: 1
kern.features.pps_sync: 1
kern.features.quota: 1
kern.features.scbus: 1
kern.features.softupdates: 1
kern.features.stack: 1
kern.features.sysv_msg: 1
kern.features.sysv_sem: 1
kern.features.sysv_shm: 1
kern.features.ufs_acl: 1
With his patches we have a total of 84 kernel features which can be queried (obviously I do not have all optional options enabled in the kernel which produces this output). All of the features also have a description, and it is easy to add more features. As an example I present what is necessary to produce the kern.features.stack output:
./kern/subr_stack.c:FEATURE(stack, “Support for capturing kernel stack”);
There is also a little userland application (and a library interface) which allows to query several features from scripts/applications with the possibility to pretend a feature is not there (the requirement for this was for ports; pretending a feature is there if it is not was ruled out because such run-time detection is only necessary for things which have to run soon and pretending some feature is there while it is not will cause big problems). Unfortunately the man page for the application is not yet ready, but I’m sure you can figure out how to use it.
The names of the features and the description follows an easy scheme, what is written down in NOTES is used as a name and a description for the feature (an exception is geom_part_X, there we decided to use a common theme (“GEOM partitioning class for XXX”) which is distinct from the corresponding geom_X class). If you have complains about what is used in a specific feature, do not complain to him: change it in NOTES and the feature will follow.
If you have questions, suggestions, or some other interest to contact him, his FreeBSD address is kibab@. Feel free to encourage him to go ahead with the next steps (finishing the man page, splitting up the patches into sensible pieces and presenting them on appropriate mailinglists for review).
GD Star Rating
loading…
GD Star Rating
loading…
Tags: autoload,
google,
gsoc,
kernel module,
kernel stack,
library interface,
posix,
priority scheduling,
shm,
subr —
I stumbled over Google’s new RE engine. Unfortunately it is not handling backreferences, so it is not a drop-in replacement for the regular expressions code in FreeBSD. It has a POSIX mode, but this only seems to be enough for the egrep syntax. For people which need backreferences, they refer to the Google Chrome’s RE engine irregexp which in turn references a paper from 2007 which is titled Regular Expression Matching Can Be Simple And Fast.
The techniques in the paper can not be applied to the irregexp engine, but maybe could help to speed up awk, egrep and similar programs.
I think it would be interesting to compare those recent developments to what we have in FreeBSD, and if they are faster, to see if it is possible to improve the FreeBSD implementation based upon them (either by writing new code, or by importing existing code, depending on the corresponding license and the language the code is written in).
Maybe a candidate for the GSoC?
GD Star Rating
loading…
GD Star Rating
loading…
Tags: egrep,
freebsd,
google,
google engine,
gsoc,
posix,
recent developments,
regular expression matching,
regular expressions,
syntax —
Today I had again some energy to look at why mono fails to build on FreeBSD-current.
I decided to do a debug-build of mono. This did not work initially, I had to produce some patches.
Does this mean nobody is doing debug builds of mono on FreeBSD?
I have to say, this experience with lang/mono is completely unsatisfying.
Ok, bottom line, either the debug build seems to prevent a race condition in most cases (I had a lot less lockups for each of the two builds I did).
Whatever it is, I do not care ATM (if the configure stuff is looking at the architecture of the system, it may be the case that the i386-portbld-freebsdX does not enable some important stuff which would be enabled when run with i486-portbld-freebsdX or better). Here are the patches I used in case someone is interested (warning, copy&paste converted tabs to spaces, you also have to apply the map.c (a generated file… maybe a touch of the right file would allow to apply this patch in the normal patch stage) related stuff when the build fails, else there is some parser error in mono):
--- mcs/class/Mono.Posix/Mono.Unix/UnixProcess.cs.orig 2010-01-29 11:34:00.592323482 +0100
+++ mcs/class/Mono.Posix/Mono.Unix/UnixProcess.cs 2010-01-29 11:34:18.540607357 +0100
@@ -57,7 +57,7 @@ namespace Mono.Unix {
int r = Native.Syscall.waitpid (pid, out status,
Native.WaitOptions.WNOHANG | Native.WaitOptions.WUNTRACED);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
- return r;
+ return status;
}
public int ExitCode {
--- mono/io-layer/processes.c.orig 2010-01-29 11:36:08.904331535 +0100
+++ mono/io-layer/processes.c 2010-01-29 11:42:21.819159544 +0100
@@ -160,7 +160,7 @@ static gboolean waitfor_pid (gpointer te
ret = waitpid (process->id, &status, WNOHANG);
} while (errno == EINTR);
- if (ret <= 0) {
+ if (ret == 0 || (ret < 0 && errno != ECHILD)) {
/* Process not ready for wait */
#ifdef DEBUG
g_message ("%s: Process %d not ready for waiting for: %s",
@@ -169,6 +169,17 @@ static gboolean waitfor_pid (gpointer te
return (FALSE);
}
+
+ if (ret < 0 && errno == ECHILD) {
+#ifdef DEBUG
+ g_message ("%s: Process %d does not exist (anymore)", __func__,
+ process->id);
+#endif
+ /* Faking the return status. I do not know if it is correct
+ * to assume a successful exit.
+ */
+ status = 0;
+ }
#ifdef DEBUG
g_message ("%s: Process %d finished", __func__, ret);
--- mono/metadata/mempool.c.orig 2010-01-29 11:58:16.871052861 +0100
+++ mono/metadata/mempool.c 2010-01-29 12:30:45.143367454 +0100
@@ -212,12 +212,14 @@ mono_backtrace (int size)
EnterCriticalSection (&mempool_tracing_lock);
g_print ("Allocating %d bytesn", size);
+#if defined(HAVE_BACKTRACE_SYMBOLS)
symbols = backtrace (array, BACKTRACE_DEPTH);
names = backtrace_symbols (array, symbols);
for (i = 1; i < symbols; ++i) {
g_print ("t%sn", names [i]);
}
free (names);
+#endif
LeaveCriticalSection (&mempool_tracing_lock);
}
--- mono/metadata/metadata.c.orig 2010-01-29 11:59:38.552316989 +0100
+++ mono/metadata/metadata.c 2010-01-29 12:00:43.957337476 +0100
@@ -3673,12 +3673,16 @@ mono_backtrace (int limit)
void *array[limit];
char **names;
int i;
+#if defined(HAVE_BACKTRACE_SYMBOLS)
backtrace (array, limit);
names = backtrace_symbols (array, limit);
for (i =0; i < limit; ++i) {
g_print ("t%sn", names [i]);
}
g_free (names);
+#else
+ g_print ("No backtrace available.n");
+#endif
}
#endif
--- support/map.c.orig 2010-01-29 12:05:22.374653708 +0100
+++ support/map.c 2010-01-29 12:10:29.024412452 +0100
@@ -216,7 +216,7 @@
#define _cnm_dump(to_t, from) do {} while (0)
#endif /* def _CNM_DUMP */
-#ifdef DEBUG
+#if defined(DEBUG) && !defined(__FreeBSD__)
#define _cnm_return_val_if_overflow(to_t,from,val) G_STMT_START {
int uns = _cnm_integral_type_is_unsigned (to_t);
gint64 min = (gint64) _cnm_integral_type_min (to_t);
GD Star Rating
loading…
GD Star Rating
loading…
Tags: amp,
atm,
bottom line,
debugging,
lt,
parser error,
patches,
pid,
posix,
public int —
I try to build mono on FreeBSD-current (it is a dependency of some GNOME program). Unfortunately this does not work correctly.
What I see are hangs of the build. If I stop the build when it hangs and restart it, it will continue and succeed to process the build steps a little bit further, but then it hangs again.
If I ktrace the hanging process, I see that there is a call to wait returning with the error message that the child does not exist. Then there is a call to nanosleep.
It looks to me like this process missed some SIGCLD (or is waiting for something which did not exist at all), and a loop is waiting for a child to exit. This loop probably has no proper condition for the fact that there is no such child (anymore). As such it will stay forever in this loop.
So I grepped a litte bit around in mono and found the following code in <mono-src-dir>/mcs/class/Mono.Posix/Mono.Unix/UnixProcess.cs:
public void WaitForExit ()
{
int status;
int r;
do {
r = Native.Syscall.waitpid (pid, out status, (Native.WaitOptions) 0);
} while (UnixMarshal.ShouldRetrySyscall (r));
UnixMarshal.ThrowExceptionForLastErrorIf (r);
}
This does look a little bit as it could be related to the problem I see, but ShouldRetrySyscall only returns true if the errno is EINTR. So this looks correct.
I looked a little bit more at this file and it looks like either I do not understand the semantic of this language, or GetProcessStatus does return the returnvalue of the waitpid call instead of the status (which is not what it shall return to my understanding). If I am correct, it can not really detect the status of a process. It would be very bad if such a fundamental thing went unnoticed in mono… which does not put a good light on the unit-tests (if any) or the general testing of mono. For this reason I hope I am wrong.
I did not stop there, as this part does not look like it is the problem. I found the following in mono/io-layer/processes.c:
static gboolean waitfor_pid (gpointer test, gpointer user_data)
{
...
do {
ret = waitpid (process->id, &status, WNOHANG);
} while (errno == EINTR);
if (ret <= 0) {
/* Process not ready for wait */
#ifdef DEBUG
g_message ("%s: Process %d not ready for waiting for: %s",
__func__, process->id, g_strerror (errno));
#endif
return (FALSE);
}
#ifdef DEBUG
g_message ("%s: Process %d finished", __func__, ret);
#endif
process->waited = TRUE;
...
}
And here we have the problem, I think. I changed the (ret <= 0) to (ret == 0 || (ret < 0 && errno != ECHILD)). This will not really give the correct status, but at least it should not block anymore and I should be able to see the difference during the build.
And now after testing, I see a difference, but the problem is still there. The wait with ECHILD is gone in the loop, but there is still some loop with a semaphore operation:
62960 mono CALL clock_gettime(0xd,0xbf9feef8)
62960 mono RET clock_gettime 0
62960 mono CALL semop(0x20c0000,0xbf9feef6,0x1)
62960 mono RET semop 0
62960 mono CALL semop(0x20c0000,0xbf9feef6,0x1)
62960 mono RET semop 0
62960 mono CALL semop(0x20c0000,0xbf9feef6,0x1)
62960 mono RET semop 0
62960 mono CALL semop(0x20c0000,0xbf9feef6,0x1)
62960 mono RET semop 0
62960 mono CALL nanosleep(0xbf9fef84,0)
62960 mono RET nanosleep 0
62960 mono CALL clock_gettime(0xd,0xbf9feef8)
62960 mono RET clock_gettime 0
62960 mono CALL semop(0x20c0000,0xbf9feef6,0x1)
62960 mono RET semop 0
62960 mono CALL semop(0x20c0000,0xbf9feef6,0x1)
62960 mono RET semop 0
62960 mono CALL semop(0x20c0000,0xbf9feef6,0x1)
62960 mono RET semop 0
62960 mono CALL semop(0x20c0000,0xbf9feef6,0x1)
62960 mono RET semop 0
62960 mono CALL nanosleep(0xbf9fef84,0)
OK, there is more going on. I think someone with more knowledge about mono should have a look at this (do not only look at this semop thing, but also look why it loses a child).
GD Star Rating
loading…
GD Star Rating
loading…
Tags: error message,
fundamental thing,
gnome program,
little bit,
pid,
posix,
public void,
returnvalue,
syscall,
unit tests —