tag:blogger.com,1999:blog-22203572206384642092024-03-13T08:17:03.000-07:00sergey senozhatsky's blogAnonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.comBlogger110125tag:blogger.com,1999:blog-2220357220638464209.post-11045354707928993532013-11-25T01:17:00.002-08:002013-11-25T01:17:27.699-08:00 Release of PowerTOP v2.5<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="tG QF">
</div>
<div class="Ct">
We are pleased to announce the <b>release of PowerTOP v2.5</b>.<br /><br />2.5 saw a number of fixes and improvements.<br />Thanks to everyone who helped and contributed.<br /><br />From the top of my head, there are 2 long awaited improvements we've been asked for:<br />0) powertop --auto-tune<br />toggle all tunables to good state and exit.<br /><br />1) show tunables toggle commands<br />e.g.<br />echo 'auto' > '/sys/bus/pci/devices/0000:ff:00.0/power/control';<br /><br /><br />For those of you who are interested in numbers<br /><br />git diff --stat 99121654d..HEAD<br /><br /><b>67 files changed, 6116 insertions(+), 3895 deletions(-)</b><br /><br />not bad.<br /><br /><br />release announcement:<br /><a class="ot-anchor" href="https://01.org/powertop/blogs/kristen/2013/powertop-v2.5-released" rel="nofollow">https://01.org/powertop/blogs/kristen/2013/powertop-v2.5-released</a></div>
</div>
Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-47718926019025556772013-10-20T14:12:00.002-07:002013-10-20T14:17:50.963-07:00what was that...<div dir="ltr" style="text-align: left;" trbidi="on">
gosh... 2013 Australian MotoGP round is the most ridiculous and confusing<br />
race I've ever seen. split race with mandatory bike swap, black flags... really? </div>
Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-101521197722567152013-09-06T04:05:00.003-07:002013-09-06T04:06:49.575-07:00/proc/$PID/stat overflowed task utime<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
If you happen to see a bogus task run time (overflowed user time)/cpu usage/etc. in <b>top</b><br />
or <b>ps</b> output with recent kernels<br />
<br />
<div style="text-align: left;">
<span style="font-size: x-small;"> $ ps aux | grep rcu<br /> root 8 0.0 0.0 0 0 ? S 12:42 0:00 [rcuc/0]<br /> root 9 0.0 0.0 0 0 ? S 12:42 0:00 [rcub/0]<br /> root 10 <b>62422329</b> 0.0 0 0 ? R 12:42 <b>21114581:37</b> [rcu_preempt]<br /> root 11 0.1 0.0 0 0 ? S 12:42 0:02 [rcuop/0]<br /> root 12 <b>62422329</b> 0.0 0 0 ? S 12:42 <b>21114581:35</b> [rcuop/1]<br /> root 10 <b>62422329</b> 0.0 0 0 ? R 12:42 <b>21114581:37</b> [rcu_preempt]</span></div>
<div style="text-align: left;">
<span style="font-size: x-small;"><br /></span></div>
<div style="text-align: left;">
<span style="font-size: x-small;"><br /></span></div>
or<br />
<br />
<br />
<span style="font-size: x-small;">cat /proc/10/stat<br />10 (rcu_preempt) S 2 0 0 0 -1 2129984 0 0 0 0 <b>1844674407370</b> 477 0 0 20 0 1 0 10 0 0 18446744073709551615 0 0 0 0 0 0 0 2147483647 0</span><br />
<br />
<br />
then you probably would be interested in cherry picking commit <b>5a8e01f8fa51f5cbce8f37acc050eb2319d12956 </b><br />
by Stanislaw Gruszka (or just wait for the next stable release).</div>
Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-14186472626104273832013-05-26T07:35:00.001-07:002013-05-26T07:36:54.687-07:00snprintf()<br />
Now I know that<br /><br />
<div style="text-align: justify;">
<blockquote>
The functions snprintf() and vsnprintf() do not write more than size bytes (including the terminating null byte ('\0')). If the output was truncated due to this limit then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available. Thus, <b>a return value of size or more means that the output was truncated</b>.</blockquote>
</div>
Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-25120918148699813232013-01-12T05:40:00.000-08:002013-01-12T05:41:07.301-08:00gcc: moving to compile time<span style="font-size: x-small;">NOTE: below is gcc specific.</span><br />
<br />
<br />
It's always hard to come up with examples, let's say we have a processing item<br />
<br />
<span style="color: #4c1130;"><span style="font-size: x-small;">struct __item {<br /> int flags;<br /> int prio;<br /> void *priv;<br />};</span></span><br />
a number of possible types<br />
<br />
<span style="color: #4c1130;"><span style="background-color: white;"><span style="font-size: x-small;">#define IT_TYPE_A (1 << 4)<br />#define IT_TYPE_B (1 << 3)<br />#define IT_TYPE_C (1 << 2)<br />#define IT_TYPE_ANY (1 << 1)</span></span></span><br />
<br />
and a usage example:<br />
<br />
<span style="color: #4c1130;"><span style="font-size: x-small;"> struct __item it = {<br /> .flags = IT_TYPE_ANY | IT_TYPE_C,<br /> .prio = 0,<br /> .priv = "cron item processing",<br /> };<br /> [..]<br /> process_item(&it);</span></span><br />
<br />
<br />
Let's say, we deprecate (<i><span style="font-size: x-small;">you know, because of reasons(tm)</span></i>) <span style="font-size: x-small;"><b>IT_TYPE_ANY</b></span> field.<br />
Now we need to check and correct passed items each time <span style="font-size: x-small;"><b>process_item</b></span>() called,<br />
even for compile-time known flag values, like the above one. In a trivial situation <br />
this might be almost free operation, but it depends.<br />
<br />
A solution could be to extract a<i> happy path </i>-- for compile time known<br />
values, and a <i>slow path</i> -- for run-time checks and adjustments.<br />
<br />
IOW, we need to hide our original <b>process_item()</b> and define new function<br />
<br />
<span style="color: #4c1130;"><span style="font-size: x-small;"><b>__fortify_function</b> int process_item(struct __item *it)<br />{<br /> if (<b>__builtin_constant_p </b>(it->flags)) {<br /> if ((it->flags & IT_TYPE_ANY) != 0) {<br /> <b>__warn_type_any_deprecated</b>();<br /> it->flags &= ~IT_TYPE_ANY;<br /> it->flags |= IT_TYPE_A;<br /><br /> <span style="color: #274e13;">/** something important **/</span><br /> }<br /> }<br /> return <span style="color: #990000;"><b>__process_item</b></span>(it);<br />}</span></span><br />
<br />
that'd be able to test and correct passed items. <span style="font-size: x-small;"><b>__builtin_constant_p</b></span>() is a <br />
gcc internal, that returns 1 if compiler can prove that value is correct and known <br />
at compile time (with some exceptions), and <span style="font-size: x-small;"><b>__fortify_function</b></span> is <span style="font-size: x-small;"><b><br />__extern_always_inline __attribute_artificial__</b></span>.<br />
<br />
We also might be interested in informing programmer about usage of a<br />
deprecated flag value, therefore we define empty function<br />
<br />
<span style="color: #4c1130;"><span style="font-size: x-small;">extern void __attribute__((deprecated)) __warn_type_any_deprecated() {};</span></span><br />
<br />
<br />
Now compiler fires a warning each time it sees <span style="font-size: x-small;"><b>__warn_type_any_deprecated</b></span>():<br />
<br />
<span style="color: #134f5c;"><span style="font-size: x-small;">gcc -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -O2 test.c -o a.out<br />In file included from test.c:21:0:<br />item.h: In function ‘process_item’:<br /><b>item.h:34:4: warning: ‘__warn_type_any_deprecated’ is deprecated (declared at item.h:25) [-Wdeprecated-declarations]</b></span></span><br />
<br />
The good thing about this is that for <span style="font-size: x-small;"><b>__builtin_constant_p</b></span>() case compiler will try<br />
to do all checks and flag adjustments behind the scene, producing code directly<br />
for "<span style="font-size: x-small;"><b>IT_TYPE_A | IT_TYPE_C</b></span>" case:<br />
<br />
<span style="color: #20124d;"><span style="font-size: x-small;"> movl $0x0,0x4(%rsp)<br /> movq $0x4006be,0x8(%rsp)<br /> movl <b>$0x14,(%rsp)</b><br /> callq 0x400580 <<b>__process_item</b>></span></span><br />
<br />
note <span style="color: #7f6000;"><span style="font-size: x-small;">movl $0x14,(%rsp)</span></span> instead of <span style="color: #7f6000;"><span style="font-size: x-small;">movl $0x6,(%rsp)</span></span>.<br />
<br />
Developer, however, is still able to ignore (or simply miss) warning, so<br />
for radical cases we can fail build process.<br />
<br />
<b><span style="font-size: x-small;">sys/cdefs.h</span> </b>header file contains several defines that could be useful<br />
<span style="color: #783f04;"><span style="font-size: x-small;"><br />145 #if __GNUC_PREREQ (4,3)<br />146 # define <b>__warndecl</b>(name, msg) \<br />147 extern void name (void) __attribute__((__warning__ (msg)))<br />148 # define <b>__warnattr</b>(msg) __attribute__((__warning__ (msg)))<br />149 # define <b>__errordecl</b>(name, msg) \<br />150 extern void name (void) __attribute__((__error__ (msg)))<br />151 #else <br />152 # define <b>__warndecl</b>(name, msg) extern void name (void)<br />153 # define <b>__warnattr</b>(msg)<br />154 # define <b>__errordecl</b>(name, msg) extern void name (void)<br />155 #endif</span></span><br />
<br />
<br />
Changing <span style="font-size: x-small;"><b>__warn_type_any_deprecated</b></span>() prototype to <br />
<br />
<span style="color: #4c1130;"><span style="font-size: x-small;">__warndecl (__warn_type_any_deprecated, <span style="color: #990000;">"\n\tWARNING: TYPE ANY has been deprecated"</span>);</span></span><br />
<br />
will change output to:<br />
<br />
<span style="color: #274e13;"><span style="font-size: x-small;">gcc -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -O2 test.c -o a.out<br />In file included from test.c:21:0:<br />In function ‘process_item’,<br /> inlined from ‘main’ at test.c:63:14:<br /><b>item.h:34:30: warning: call to ‘__warn_type_any_deprecated’ declared with attribute warning: <br /> <span style="color: #990000;">WARNING: TYPE ANY has been deprecated</span> [enabled by default]</b></span></span><br />
<br />
and fail linkage (pretty hard to ignore), because <span style="font-size: x-small;"><b>__warndecl</b></span>() declares function<br />
w/o body:<br />
<br />
<span style="color: #990000;"><span style="font-size: x-small;">test.c:(.text.startup+0x1d): undefined reference to `__warn_type_any_deprecated'</span></span><br />
<br />Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-76501322590208540452012-12-27T04:56:00.005-08:002012-12-27T04:57:07.068-08:00stat() nanosecond time resolution<span style="font-size: x-small;"><br /><span style="color: #0c343d;"><span style="font-size: x-small;">$ stat foo <br />[..]<br />Access: 2012-12-27 15:07:08<b>.020388663</b> +0300<br />Modify: 2012-12-27 15:07:08<b>.020388663</b> +0300<br />Change: 2012-12-27 15:07:08<b>.020388663</b> +0300</span></span><br /><br />where does nanosecond precision come from?<br /><br /><b>man 2 stat</b><br /><br /><span style="font-size: x-small;"><span style="color: #20124d;"> struct stat {<br /> dev_t st_dev; <span style="color: #0c343d;"> <span style="color: #274e13;">/* ID of device containing file */</span></span><br /> ino_t st_ino; <span style="color: #274e13;">/* inode number */</span><br /> mode_t st_mode; <span style="color: #274e13;">/* protection */</span><br /> nlink_t st_nlink; <span style="color: #274e13;">/* number of hard links */</span><br /> uid_t st_uid; <span style="color: #274e13;">/* user ID of owner */</span><br /> gid_t st_gid; <span style="color: #274e13;">/* group ID of owner */</span><br /> dev_t st_rdev; <span style="color: #274e13;">/* device ID (if special file) */</span><br /> off_t st_size; <span style="color: #274e13;"> /* total size, in bytes */</span><br /> blksize_t st_blksize; <span style="color: #274e13;">/* blocksize for file system I/O */</span><br /> blkcnt_t st_blocks; <span style="color: #274e13;">/* number of 512B blocks allocated */</span><br /> time_t st_atime; <span style="color: #274e13;">/* time of last access */</span><br /> time_t st_mtime; <span style="color: #274e13;">/* time of last modification */</span><br /> time_t st_ctime; <span style="color: #274e13;">/* time of last status change */</span><br /> };</span></span><br /><br />as we can see, stat struct contains ctime/mtime/atime, which are time_t, so it's quiet<br />unlikely to store nanosecond resolution.<br /><br />The note part says:</span><br />
<blockquote class="tr_bq">
<span style="background-color: #fff2cc;"><span style="font-size: x-small;"><span style="font-size: x-small;">Since kernel 2.5.48, the stat structure supports nanosecond resolution<br />for the three file timestamp fields.</span></span><span style="font-size: x-small;"><span style="font-size: x-small;"> Glibc exposes the nanosecond component<br />of each field using names of the form st_atim.tv_nsec if the _BSD_SOURCE</span> <br /><span style="font-size: x-small;">or<span style="font-size: x-small;"> </span> _SVID_SOURCE feature test macro is defined. These fields are specified in<br /> POSIX.1-2008, and, starting</span></span> <span style="font-size: x-small;"><span style="font-size: x-small;">with version 2.12, glibc also exposes these field <br />names if _POSIX_C_SOURCE is defined with the value 200809L or</span></span> <span style="font-size: x-small;"><span style="font-size: x-small;">greater, or<br /> _XOPEN_SOURCE is defined with the value 700 or greater. If none of the <br />aforementioned macros are<span style="font-size: x-small;"> </span></span></span><span style="font-size: x-small;"><span style="font-size: x-small;">defined, then the nanosecond values are exposed<span style="font-size: x-small;"> </span><br /> with names of the form st_atimensec. On file systems that do</span></span> <span style="font-size: x-small;"><span style="font-size: x-small;">not support <br />subsecond timestamps, the nanosecond fields are returned with the value 0.</span></span></span></blockquote>
<span style="font-size: x-small;"><br /><br />GLIBC defines <b>struct stat</b> as<br /><br /><span style="color: #073763;">struct stat<br />[..]<br /> #<b>if defined __USE_MISC || defined __USE_XOPEN2K8</b><br /><span style="color: #274e13;"> /* Nanosecond resolution timestamps are stored in a format<br /> equivalent to 'struct timespec'. This is the type used<br /> whenever possible but the Unix namespace rules do not allow the<br /> identifier 'timespec' to appear in the <sys stat.h="stat.h"> header.<br /> Therefore we have to handle the use of this header in strictly<br /> standard-compliant sources special. */</sys></span><br /> struct <b>timespec</b> st_atim; <span style="color: #274e13;">/* Time of last access. */</span><br /> struct <b>timespec</b> st_mtim; <span style="color: #274e13;"> /* Time of last modification. */</span><br /> struct <b>timespec </b>st_ctim; <span style="color: #274e13;">/* Time of last status change. */</span><br /> <b> # define st_atime st_atim.tv_sec</b> <span style="color: #274e13;">/* Backward compatibility. */</span><br /> <b># define st_mtime st_mtim.tv_sec</b><br /> <b># define st_ctime st_ctim.tv_sec</b><br /> #else<span style="color: #274e13;"><br /> <span style="color: #073763;">__time_t st_atime;</span> </span> <span style="color: #274e13;">/* Time of last access. */</span><br /> <span style="color: #741b47;"><b>unsigned long int st_atimensec;</b></span> <span style="color: #274e13;"> /* Nscecs of last access. */</span><br /> __time_t st_mtime; <span style="color: #274e13;">/* Time of last modification. */</span><br /> <b><span style="color: #741b47;">unsigned long int st_mtimensec;</span> </b> <span style="color: #274e13;">/* Nsecs of last modification. */</span><br /> __time_t st_ctime; <span style="color: #274e13;"> /* Time of last status change. */</span><br /> <span style="background-color: white;"></span><span style="color: #741b47;"><span style="background-color: white;"><b>unsigned long int st_ctimensec;</b></span></span> <span style="color: #274e13;"> /* Nsecs of last status change. */</span><br /> <b>#endif</b><br />[..]</span><br /><br />where <b>MISC</b> or <b>XOPEN2K8</b> defs are coming from<br /><br /><b>glibc/include/features.h</b><br /><br /><span style="color: #073763;"> #if <b>(_POSIX_C_SOURCE - 0) >= 200809L</b><br /> # define <b>__USE_XOPEN2K8</b> 1 <br /> # undef _ATFILE_SOURCE<br /> # define _ATFILE_SOURCE<span style="font-size: x-small;"> </span>1<br /> #endif</span><br /><br />or<br /><br /><span style="color: #073763;"><span style="background-color: white;"> # if (_XOPEN_SOURCE - 0) >= 600<br /> # <b> if (_XOPEN_SOURCE - 0) >= 700</b><br /> # define <b>__USE_XOPEN2K8</b> 1<br /> # define __USE_XOPEN2K8XSI 1<br /> # endif<br /><br /><br /> #if defined <b>_BSD_SOURCE</b> || defined _SVID_SOURCE<br /> # define <b>__USE_MISC</b> 1 <br /> #endif</span></span><br /><br /><br />So it seems, that <span style="color: #073763;">'if defined __USE_MISC || defined __USE_XOPEN2K8' </span>or<br /><span style="color: #073763;">'if defined _BSD_SOURCE'</span> is sufficient. However, the real world code(tm) is a bit more<br />complicated. Here is a small part of core-utils' stat:<br /><br /><br />[..]<br /><span style="color: #073763;"><span style="color: #274e13;"> /* STAT_TIMESPEC (ST, ST_XTIM) is the ST_XTIM member for *ST of type<br /> struct timespec, if available. If not, then STAT_TIMESPEC_NS (ST,<br /> ST_XTIM) is the nanosecond component of the ST_XTIM member for *ST,<br /> if available. ST_XTIM can be st_atim, st_ctim, st_mtim, or st_birthtim<br /> for access, status change, data modification, or birth (creation)<br /> time respectively.<br /><br /> These macros are private to stat-time.h. */</span><br /><span style="color: #783f04;"> #if defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC<br /> # ifdef TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC</span><br /> # define <b>STAT_TIMESPEC</b>(st, st_xtim) ((st)->st_xtim)<br /><span style="color: #783f04;"> # else</span><br /> # define <b>STAT_TIMESPEC_NS</b>(st, st_xtim) ((st)->st_xtim.tv_nsec)<br /><span style="color: #783f04;"> # endif<br /> #elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC</span><br /> # define <b>STAT_TIMESPEC</b>(st, st_xtim) ((st)->st_xtim##<span style="color: #cc0000;"><b>espec</b></span>)<br /><span style="color: #783f04;"> #elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC </span> <br /> # define <b>STAT_TIMESPEC_NS</b>(st, st_xtim) ((st)->st_xtim##<span style="color: #cc0000;"><b>ensec</b></span>)<br /><span style="color: #783f04;"> #elif defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC</span><br /> # define <b>STAT_TIMESPEC_NS</b>(st, st_xtim) ((st)-><span style="color: #cc0000;"><b>st_xtim.st__tim.tv_nsec</b></span>)<br /><span style="color: #783f04;"> #endif</span><br /><br /><br /><span style="color: #274e13;"> /* Return the nanosecond component of *ST's status change time. */</span><br /> static inline long int<b><br /> get_stat_ctime_ns </b>(<b>struct stat const *st</b>)<br /> {<br /><span style="color: #783f04;"> # if defined STAT_TIMESPEC</span><br /> return STAT_TIMESPEC (st, st_ctim).tv_nsec;<br /><span style="color: #783f04;"> # elif defined STAT_TIMESPEC_NS</span><br /> return STAT_TIMESPEC_NS (st, st_ctim);<br /><span style="color: #783f04;"> # else</span><br /> return 0;<br /><span style="color: #783f04;"> # endif</span><br /> }</span><br />[..]</span>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-87090011652957932662012-05-28T14:57:00.000-07:002012-05-28T14:57:53.287-07:00GCC vector types<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Apparently GCC has vector types for C language. Moreover, GCC 4.7 allows<br />
to use vector generating element while performing operations with vector types.<br />
<br />
Suppose we have<br />
<br />
<b><span style="color: #073763; font-size: x-small;">typedef int intvect __attribute__ ((vector_size (32)))<br /><br />intvec a, b = {1,2,3,4,5,6,7,8};</span></b><br />
<br />
<br />
Operation with vector generating element will be:<br />
<br />
<b style="color: #073763;"><span style="font-size: x-small;">a = b + 2;</span></b><br />
<br />
which literally means:<br />
<br />
<b><span style="color: #073763; font-size: x-small;">vector a{2,2,2,2,2,2,2,2} + vector b{1,2,3,4,5,6,7,8}</span></b><br />
<br />
<br />
As it often happens, the neat stuff is hidden behind. Part of generated<br />
assembler code:<br />
<br />
<span style="color: #073763; font-size: x-small;"> movl $0x1,0x48(%rsp)<br /> movl $0x2,0x4c(%rsp)<br /> movl $0x3,0x50(%rsp)<br /> movl $0x4,0x54(%rsp)<br /> movl $0x5,0x58(%rsp)<br /> movl $0x6,0x5c(%rsp)<br /> movl $0x7,0x60(%rsp)<br /> movl $0x8,0x64(%rsp)<br /> movdqa 0x48(%rsp),%xmm1<br /> movl $0x2,-0x38(%rsp)<br /> movl $0x2,-0x34(%rsp)<br /> movl $0x2,-0x30(%rsp)<br /> movl $0x2,-0x2c(%rsp)<br /> movl $0x2,-0x28(%rsp)<br /> movl $0x2,-0x24(%rsp)<br /> movl $0x2,-0x20(%rsp)<br /> movl $0x2,-0x1c(%rsp)<br /> movdqa -0x38(%rsp),%xmm0<br /> paddd %xmm0,%xmm1<br /> movdqa 0x58(%rsp),%xmm2<br /> movl $0x2,-0x58(%rsp)<br /> movl $0x2,-0x54(%rsp)<br /> movl $0x2,-0x50(%rsp)<br /> movl $0x2,-0x4c(%rsp)<br /> movl $0x2,-0x48(%rsp)<br /> movl $0x2,-0x44(%rsp)<br /> movl $0x2,-0x40(%rsp)<br /> movl $0x2,-0x3c(%rsp)</span><br />
<br />
<br />
I really like how they utilize CPU's out-of-order and data prefetching features <br />
by filling pipeline with mov-s with high probability of simultaneous execution<br />
instead of several loops.<br />
<span style="font-size: x-small;"><br /></span><br />
<blockquote style="background-color: #fff2cc;">
<span style="font-size: x-small;">"The core's ability to execute instructions out of order is a key factor in enabling</span><br />
<span style="font-size: x-small;">parallelism. This feature enables the processor to reorder instructions so that if</span><br />
<span style="font-size: x-small;">one µop is delayed while waiting for data or a contended resource, other µops that</span><br />
<span style="font-size: x-small;">appear later in the program order may proceed. This implies that when one portion</span><br />
<span style="font-size: x-small;">of the pipeline experiences a delay, the delay may be covered by other operations</span><br />
<span style="font-size: x-small;">executing in parallel or by the execution of µops queued up in a buffer."</span></blockquote>
<br />
<br />
Good example is glibc's strncmp:<br />
<br />
<span style="color: #073763; font-size: x-small;"> STRNCMP (const char *s1, const char *s2, size_t n)<br /> {<br /> unsigned char c1 = '\0';<br /> unsigned char c2 = '\0';<br /><br /> if (n >= 4)<br /> {<br /> size_t n4 = n >> 2;<br /> do<br /> {<br /> c1 = (unsigned char) *s1++;<br /> c2 = (unsigned char) *s2++;<br /> if (c1 == '\0' || c1 != c2)<br /> return c1 - c2;<br /> c1 = (unsigned char) *s1++;<br /> c2 = (unsigned char) *s2++;<br /> if (c1 == '\0' || c1 != c2)<br /> return c1 - c2;<br /> c1 = (unsigned char) *s1++;<br /> c2 = (unsigned char) *s2++;<br /> if (c1 == '\0' || c1 != c2)<br /> return c1 - c2;<br /> c1 = (unsigned char) *s1++;<br /> c2 = (unsigned char) *s2++;<br /> if (c1 == '\0' || c1 != c2)<br /> return c1 - c2;<br /> } while (--n4 > 0);<br /> n &= 3;<br /> }<br /><br /> while (n > 0)<br /> {<br /> c1 = (unsigned char) *s1++;<br /> c2 = (unsigned char) *s2++;<br /> if (c1 == '\0' || c1 != c2)<br /> return c1 - c2;<br /> n--;<br /> }<br /> return c1 - c2;<br /> }</span></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-3998515689647389302012-04-17T08:38:00.002-07:002012-04-17T13:30:04.471-07:00GCC: new inter-procedural constant propagation pass<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
GCC 4.7 has "the inter-procedural constant propagation pass" rewritten, which<br />
brought generic function specialization to C world.<br />
<br />
Suppose, we have the following example:<br />
<br />
<blockquote class="tr_bq" style="background-color: #cfe2f3;">
<span style="font-size: x-small;"> void foo(bool f)<br /> {<br /> char *p;<br /> if (f) {<br /> p = (char *) malloc(256);<br /> if (!p) {<br /> printf("Mem alloc error\n");<br /> return;<br /> }<br /> /* something extremly valuable */<br /> free(p);<br /> } else {<br /> p = (char *) malloc(256);<br /> if (!p) {<br /> printf("Mem alloc error\n");<br /> return;<br /> }<br /> /* something very important */<br /> free(p);<br /> }<br />}<br /><br /><br />int main()<br />{<br /> foo(TRUE);<br /> foo(FALSE);<br /> return 0;<br />}</span> </blockquote>
<br />
GCC now able to produce the following main():<br />
<br />
(gdb) disassemble main<br />
<span style="font-size: x-small;"><+0>: push %rax<br /><+1>: callq 0x4005cc <<b>foo.part.0</b>><br /><+6>: xor %edi,%edi<br /><+8>: callq 0x400649 <<b>foo</b>><br /><+13>: xor %eax,%eax<br /><+15>: pop %rdx<br /><+16>: retq </span><br />
<br />
<br />
Note, that GCC has actually generated two functions:<br />
-- foo.part.0 at <b>0x4005cc</b><br />
-- foo at <b>0x400649</b><br />
<br />
for each possible arg values: TRUE and FALSE.<br />
<br />
Since compiler now changes function call code it has to protect himself from "incorrect"<br />
outside calls, e.g. <b>foo(TRUE)</b> instead of <b>foo.part.0(TRUE)</b><br />
<br />
That's the reason "master" copy of foo() has switch() at the beginning:<br />
<span style="font-size: x-small;">(gdb) disassemble <b>foo</b><br /><+0>: test %dil,%dil<br /><+3>: je 0x400653 </span><b><span style="font-size: x-small;"><foo+10</span><span style="font-size: x-small;">></span></b><br />
<span style="font-size: x-small;"><foo+10><+5>: jmpq 0x4005cc </foo+10></span><b><span style="font-size: x-small;"><foo.part.0</span><span style="font-size: x-small;">></span></b><span style="font-size: x-small;"><foo+10><b><foo.part.0></foo.part.0></b><foo.part.0><br /><+10>: push %rbx<br /><+11>: mov $0x40079e,%edi<br />[...]</foo.part.0></foo+10></span></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-86472010400560936102012-03-29T03:07:00.002-07:002012-03-29T03:58:51.084-07:00ext4 noacl mount option<div dir="ltr" style="text-align: left;" trbidi="on">
Brace your mtabs/fstabs/proc/self/mounts!<br />
The error line makes it pretty clear:<br />
<br />
<blockquote class="tr_bq" style="background-color: #fff2cc;">
EXT4-fs: Mount option "noacl" will be removed by 3.5<br />
Contact <a class="ot-anchor" href="mailto:linux-ext4@vger.kernel.org">linux-ext4@vger.kernel.org</a> if you think we should keep it.</blockquote>
</div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-33506976898626291992012-03-24T10:58:00.000-07:002012-03-24T10:58:06.506-07:00gcc 4.7.0<div dir="ltr" style="text-align: left;" trbidi="on">
Hm, is that only happens to me that the same kernel built with gcc 4.7.0<br />
is 11 MiBs bigger than the one built with gcc 4.6.0...</div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-78192307676980057962012-03-14T14:21:00.000-07:002012-03-14T14:21:09.926-07:00Josuttis on C++11<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span style="font-size: x-small;"><strong>Nicolai Josuttis </strong></span>talks about C++ and why C++ is not his favorite programming<br />
language<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;"><br /></span><br />
<div style="background-color: #fff2cc;">
<span style="font-size: x-small;"><strong>Nicolai Josuttis:</strong> You know, I didn’t follow the
standardization process of C++11. At the end of 2008 I looked first into
the new standard by comparing the C++98/03 versions of classes, such as
<tt>pair</tt> and <tt>vector</tt>, with their new versions. I was shocked. I had trouble understanding what I found: “What the hell does <tt>&&</tt>
mean in declarations?” So if you ask me about the difference, my first
answer is: Everything is different! The way you write simple programs
and the way you define complicated classes have changed dramatically.
C++11's <tt>pair<></tt>, for instance, doubled the number of lines. </span></div>
<div style="background-color: #fff2cc;">
<span style="font-size: x-small;">Nevertheless, the changes go in the right direction. C++11
consequently focuses on the power of C++ -- performance. However, it
still has the drawback of making it even harder for programmers to
design good classes. Well, it might not be harder, if you know all you
have to know; but it’s harder to know all you have to know, now. To some
extent, C++11 is a new language, and my new edition simply reflects
this change, covering both the new C++ programming style and new
classes.</span></div>
</blockquote>
<br />
Please read the full story <a href="http://www.informit.com/articles/article.aspx?p=1846582&WT.mc_id=IT_NL_Content_2012_3_7&rll=1">at informit.com</a></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-21836897898330360982012-01-20T07:10:00.000-08:002012-01-20T07:10:29.429-08:00C++11 ratio<div dir="ltr" style="text-align: left;" trbidi="on">
20.10.2 Header <ratio> synopsis</ratio><br />
<br />
<span style="font-size: x-small;">quote from <a href="http://en.cppreference.com/w/cpp/numeric/ratio/ratio">cppreference</a> </span><br />
<blockquote class="tr_bq" style="background-color: #fff2cc;">
<span style="font-size: x-small;"><span class="kw1"><br />template</span><span class="sy1"><</span></span> <span style="font-size: x-small;"><br /></span>
<br />
<div>
<span style="font-size: x-small;"><span class="mw-geshi cpp source-cpp"> std<span class="sy4">::</span><span class="kw4">intmax_t</span> <b>Num</b>, <br />
std<span class="sy4">::</span><span class="kw4">intmax_t</span> <b>Denom</b> <span class="sy1">=</span> <span class="nu0">1</span> <br />
<br />
<span class="sy1">></span> <span class="kw1">class</span> <b>ratio</b><span class="sy4">;</span></span></span><span style="font-size: x-small;"><br /></span></div>
<span style="font-size: x-small;"><br />The class template <tt>std::ratio</tt> provides compile-time rational
arithmetic support. Each instantiation of this template exactly
represents any finite rational number as long as its numerator <tt>Num</tt> and denominator <tt>Denom</tt> are representable as compile-time constants of type <span class="mw-geshi cpp source-cpp">std<span class="sy4">::</span><span class="kw4">intmax_t</span></span>.</span></blockquote>
<br />
typedefs:<br />
<blockquote class="tr_bq">
<div style="color: #0c343d;">
<span style="font-size: x-small;">typedef ratio<1, 1000000000000000000000000> <b>yocto</b>;<br />typedef ratio<1, 1000000000000000000000> <b>zepto</b>;<br />typedef ratio<1, 1000000000000000000> <b>atto</b>;<br />typedef ratio<1, 1000000000000000> <b>femto</b>;<br />typedef ratio<1, 1000000000000> <b>pico</b>;<br />typedef ratio<1, 1000000000> <b>nano</b>;<br />typedef ratio<1, 1000000> <b>micro</b>;<br />typedef ratio<1, 1000> <b>milli</b>;<br />typedef ratio<1, 100> <b>centi</b>;<br />typedef ratio<1, 10> <b>deci</b>;<br />typedef ratio< 10, 1> <b>deca</b>;<br />typedef ratio< 100, 1> <b>hecto</b>;<br />typedef ratio< 1000, 1> <b>kilo</b>;<br />typedef ratio< 1000000, 1> <b>mega</b>;<br />typedef ratio< 1000000000, 1> <b>giga</b>;<br />typedef ratio< 1000000000000, 1> <b>tera</b>;<br />typedef ratio< 1000000000000000, 1> <b>peta</b>;<br />typedef ratio< 1000000000000000000, 1> <b>exa</b>;<br />typedef ratio< 1000000000000000000000, 1> <b>zetta</b>;<br />typedef ratio<1000000000000000000000000, 1> <b>yotta</b>;</span></div>
</blockquote>
<br />
<br />
<br />
<br /></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-33543504966894858952012-01-18T03:25:00.000-08:002012-01-18T03:25:50.919-08:00ReFS<div dir="ltr" style="text-align: left;" trbidi="on">
Microsoft talks a bit about ReFS -- a new server side file system with some<br />
ZFS and Btrfs features.<br />
<br />
<a href="http://www.phoronix.com/scan.php?page=news_item&px=MTA0NDA">phoronix</a> has some good notes for those who interested in short key<br />
features list:<br />
<br />
<div style="color: #0c343d;">
<span style="font-size: x-small;">- Unlike NTFS, Microsoft ReFS does share some common traits with Btrfs.
ReFS is copy-on-write, provides integrity checksums / ECC, extended
attributes, and B-trees. The Sun/Oracle ZFS file-system also shares most
of the same features. The storage engine of ReFS is using B+ trees
exclusively compared to normal B-trees in Btrfs, with the difference of
the plus variant being records stored at the leaf-level of the tree and
keys being within the interior nodes.
<br /><br />- ReFS has similar volume/file/directory size limits to EXT4 and Btrfs.
</span>
<span style="font-size: x-small;"><br /><br />- At least for Windows 8, Microsoft is not providing any upgrade
path from NTFS to ReFS, but requires re-formatting the drive and copying
any data. Within Windows 8, ReFS is also not supported as a boot
partition or for use on removable media/drives.
</span>
<span style="font-size: x-small;"><br /><br />- Below are the official "key features of ReFS" as said by Microsoft.
</span>
<span style="font-size: x-small;"><br /></span></div>
<blockquote style="color: #0c343d;">
<span style="font-size: x-small;">- Metadata integrity with checksums
<br />- Integrity streams providing optional user data integrity
<br />- Allocate on write transactional model for robust disk updates (also known as copy on write)
<br />- Large volume, file and directory sizes
<br />- Storage pooling and virtualization makes file system creation and management easy
<br />- Data striping for performance (bandwidth can be managed) and redundancy for fault tolerance
<br />- Disk scrubbing for protection against latent disk errors
<br />- Resiliency to corruptions with "salvage" for maximum volume availability in all cases
<br />- Shared storage pools across machines for additional failure tolerance and load balancing</span></blockquote>
<span style="color: #0c343d; font-size: x-small;">
<br />- ReFS does <strong>not</strong> support <a href="http://www.phoronix.com/scan.php?page=news_item&px=MTA0MzQ">data de-duplication</a>, <a href="http://www.phoronix.com/vr.php?view=14793">copy-on-write snapshots</a>
(a ZFS and Btrfs feature, but ReFS snapshots can be done when paired
with the Microsoft Storage Spaces), file-level encryption (dropped from
NTFS), or <a href="http://www.phoronix.com/vr.php?view=15809">compression</a> (Btrfs can now do Gzip, LZO, and Snappy).
<br />
<br />- In what may partially help supporting ReFS in Linux and other
platforms, Steven Sinofsky of Microsoft says, "data stored on ReFS is
accessible through the same file access APIs on clients that are used on
any operating system that can access today’s NTFS volumes." The
upper-layer engine is nearly the same as what's found in NTFS, but it's
the underlying on-disk storage engine and format that's changed with
ReFS.
</span><br />
Read the full <a href="http://blogs.msdn.com/b/b8/archive/2012/01/16/building-the-next-generation-file-system-for-windows-refs.aspx">story</a><br />
<br /></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-84278848048210421672012-01-12T01:48:00.000-08:002012-01-12T01:50:15.165-08:00GnuPG MPILIB<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: inherit;">
<span style="font-size: small;">Looks like the linux kernel 3.3 will have GnuPG MPILIB within. </span></div>
<div style="font-family: inherit;">
<br /></div>
<blockquote class="tr_bq" style="background-color: #fff2cc;">
<span style="background-color: #fff2cc; color: black; font-size: small;">Multiprecision maths library (MPILIB) [N/m/y/?] (NEW) ?</span><br />
<br />
<span style="background-color: #fff2cc; color: black; font-size: small;">CONFIG_MPILIB:</span><br />
<br />
<span style="background-color: #fff2cc; color: black; font-size: small;">Multiprecision maths library from GnuPG.</span><br />
<span style="background-color: #fff2cc; color: black; font-size: small;">It is used to implement RSA digital signature verification,</span><br />
<span style="background-color: #fff2cc; color: black; font-size: small;">which is used by IMA/EVM digital signature extension.</span><br />
<br />
<span style="background-color: #fff2cc; color: black; font-size: small;">Symbol: MPILIB [=n]</span><br />
<span style="background-color: #fff2cc; color: black; font-size: small;">Type : tristate</span><br />
<span style="background-color: #fff2cc; color: black; font-size: small;">Prompt: Multiprecision maths library</span><br />
<span style="background-color: #fff2cc; color: black; font-size: small;"> Defined at lib/Kconfig:288</span><br />
<span style="background-color: #fff2cc; color: black; font-size: small;"> Location:</span><br />
<span style="background-color: #fff2cc; color: black; font-size: small;"> -> Library routines</span><br />
<span style="background-color: #fff2cc; color: black; font-size: small;"> Selected by: DIGSIG [=n] && KEYS [=y]</span></blockquote>
<div style="font-family: inherit;">
<br />
<br />
<blockquote class="tr_bq" style="background-color: #fff2cc;">
In-kernel signature checker (DIGSIG) [N/m/y/?] (NEW) ?<br /><br />CONFIG_DIGSIG:<br /><br />Digital signature verification. Currently only RSA is supported.<br />Implementation is done using GnuPG MPI library<br /><br />Symbol: DIGSIG [=n]<br />Type : tristate<br />Prompt: In-kernel signature checker<br /> Defined at lib/Kconfig:305<br /> Depends on: KEYS [=y]<br /> Location:<br /> -> Library routines<br /> Selects: MPILIB [=m]<br /> Selected by: INTEGRITY_DIGSIG [=n] && INTEGRITY [=n] && KEYS [=y]</blockquote>
<br style="background-color: #fff2cc;" /></div>
</div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-27754176018874925472011-12-31T05:20:00.000-08:002011-12-31T05:20:33.673-08:00Happy New Year!<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="http://static.newsland.ru/news_galleries/328/328570_15.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="451" src="http://static.newsland.ru/news_galleries/328/328570_15.jpg" width="640" /></a></div>
<br />
<br />
<span style="font-size: x-small;"><i>image via <a href="http://the-mockturtle.livejournal.com/">the mockturtle</a></i></span></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-43607862163257715532011-12-21T08:37:00.000-08:002011-12-21T08:40:17.802-08:00C/C++ alternative preprocessing tokens<div dir="ltr" style="text-align: left;" trbidi="on">
C++ has a set of alternative preprocessing tokens:<br />
<i><b>2.5/1</b></i><br />
<span style="color: #0c343d; font-size: x-small;"> and_eq &=<br /> and &&<br /> xor_eq ^=<br /> or ||</span><br />
[..]<br />
<br />
<br />
It turned out that C has them as well:<br />
<i><b>7.9</b></i><br />
<blockquote class="tr_bq" style="background-color: #fff2cc;">
<span style="font-size: x-small;">The header <b>iso646.h</b></span><span style="font-size: x-small;"> <iso646.h> defines the following eleven macros (on the left) that expand to</iso646.h></span><br />
<span style="font-size: x-small;">the corresponding tokens (on the right):</span></blockquote>
<br />
cat 4.6.3/include/<b>iso646.h</b><br />
<br />
<span style="color: #0c343d; font-size: x-small;">#ifndef _ISO646_H<br />#define _ISO646_H<br /><br />#ifndef __cplusplus<br />#define and &&<br />#define and_eq &=<br />#define bitand &<br />#define bitor |<br />#define compl ~<br />#define not !<br />#define not_eq !=<br />#define or ||<br />#define or_eq |=<br />#define xor ^<br />#define xor_eq ^=<br />#endif<br /><br />#endif</span><br />
<br /></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-61035392397478003822011-12-14T04:28:00.000-08:002011-12-14T04:28:59.109-08:00rq_of_rt_rq...<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span style="font-size: x-small;"><i> kernel/sched_rt.c</i></span><br />
<blockquote class="tr_bq">
<div style="background-color: #fff2cc;">
<span style="font-size: x-small;"> [..] </span></div>
<div style="background-color: #fff2cc;">
<span style="font-size: x-small;"> 113 static void dec_rt_migration(struct <b>sched_rt_entity *rt_se</b>, <b>struct rt_rq *rt_rq</b>)<br /> 114 {<br /> 115 if (!rt_entity_is_task(rt_se))<br /> 116 return;<br /> 117 <br /> 118 <span style="color: #660000;"> </span><b style="color: #660000;">rt_rq = &rq_of_rt_rq(rt_rq)->rt;</b><br /> 119 <br /> 120 <b>rt_rq->rt_nr_total</b>--;<br /> 121 if (rt_se->nr_cpus_allowed > 1)<br /> 122 <b>rt_rq->rt_nr_migratory</b>--;<br />[..]</span></div>
</blockquote>
<br />
Try to read `<b>rt_rq = &rq_of_rt_rq(rt_rq)->rt;</b>' fluently :-)</div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-6739044242040609012011-12-11T02:08:00.001-08:002011-12-11T02:27:25.589-08:00LinuxFr.org: Interview with Andrew Tanenbaum<div dir="ltr" style="text-align: left;" trbidi="on">
Andrew Tanenbaum <span id="goog_154123231"></span><a href="http://linuxfr.org/nodes/88229/comments/1291183">on Linux, GPL and stuff<span id="goog_154123232"></span></a><br />
<br />
<blockquote class="tr_bq" style="background-color: #fff2cc;">
<span style="font-size: x-small;"><span style="font-weight: bold;">LinuxFr.org</span> : Do you think the Linux success is a proof he was right</span><br />
<span style="font-size: x-small;">or is it unrelated?</span><br />
<br />
<span style="font-size: x-small;"><span style="font-weight: bold;">Andrew Tanenbaum</span> : No, Linux "succeeded" because BSD was frozen out of</span><br />
<span style="font-size: x-small;">the market by AT&T at a crucial time. <span style="font-weight: bold;">That's just dumb luck</span>. Also, success</span><br />
<span style="font-size: x-small;">is relative. I run a political website that ordinary people read. On that</span><br />
<span style="font-size: x-small;">site statistics show that about 5% is Linux, 30% is Macintosh (which is BSD</span><br />
<span style="font-size: x-small;">inside) and the rest is Windows. These are ordinary people, not computer</span><br />
<span style="font-size: x-small;">geeks. I don't think of 5% as that big a success story.</span></blockquote>
<br />
<br /></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-41885357697723563542011-11-28T22:04:00.001-08:002011-11-28T22:15:14.000-08:002.373<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: small;"><a href="http://www.scottaaronson.com/blog/?p=839">Scott Aaronson</a> writes:</span><span style="color: white;"><br /></span><br />
<blockquote class="tr_bq" style="background-color: #fff2cc;">
For twenty years, the fastest known algorithm to multiply two n-by-n
matrices, due to Coppersmith and Winograd, took a leisurely O(n<sup>2.376</sup>) steps. Last year, though, buried deep in his <a href="http://www.maths.ed.ac.uk/pg/thesis/stothers.pdf">PhD thesis</a> where hardly anyone saw it, Andy Stothers discussed an improvement to O(n<sup>2.374</sup>) steps. And today, <a href="http://www.cs.berkeley.edu/%7Evirgi/">Virginia Vassilevska Williams</a> of Berkeley and Stanford, released a <a href="http://www.cs.berkeley.edu/%7Evirgi/matrixmult.pdf">breakthrough paper</a> that improves the matrix-multiplication time to a lightning-fast <span style="color: black;">O(n<sup>2.37<span style="color: #ff6600;"><b>3</b></span></sup>) steps.</span></blockquote>
<br />
<span style="font-size: small;">...The world will not be the same! </span></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-7884948053788034482011-11-28T06:48:00.001-08:002011-11-28T06:53:37.065-08:00C++11 N2765: user-defined literals<div dir="ltr" style="text-align: left;" trbidi="on">
C++11 will have tons of new features and concepts. One among them is<br />
N2765: user-defined literals (scheduled for GCC 4.7). Quite possible I'm dumb<br />
and ugly, but frankly, <span style="color: #b45f06;">"user-defined literals"</span> is something I've so many doubts<br />
about. There're already lots of examples, though I haven't seen anything really<br />
neat so far (only speaking for myself).<br /><br /><br />For example:<br /><br /><span style="font-size: x-small;"><span style="color: #0c343d;">constexpr long double operator<span style="color: #b45f06;">""</span> _degrees (long double d) </span><br style="color: #0c343d;" /><span style="color: #0c343d;">{ </span><br style="color: #0c343d;" /><span style="color: #0c343d;"> return d * 0.0175;</span><br style="color: #0c343d;" /><span style="color: #0c343d;">}</span><br style="color: #0c343d;" /><br style="color: #0c343d;" /><span style="color: #0c343d;">long double pi = </span><b style="color: #0c343d;">180_degrees</b><span style="color: #0c343d;">;</span></span><br /><br />Or (<a href="http://pyevolve.sourceforge.net/wordpress/?p=2104">link</a>)<br /><br /><span style="font-size: x-small;">typedef std::map<std::string, int=""> MyMap;<br />MyMap create_map()<br />{<br /> MyMap m;<br /> m[<span style="color: #b45f06;">"lol"</span>] = 7;<br /> return m;<br />}<br /><br />auto m = create_map();<br /><br />int& operator <span style="color: #b45f06;">""</span> m(const char *key, size_t length)<br />{ <br /> return m[key];<br />}<br /><br />int main(void)<br />{<br /> std::cout << <b><span style="color: #b45f06;">"lol"</span>m </b><< std::endl;<br /> // 7<br /> "lol"m = 2;<br /> std::cout << <b><span style="color: #b45f06;">"lol"</span>m </b><< std::endl;<br /> // 2<br /> return 0;<br />}</std::string,></span><br /><br /><br />Or (<a href="http://stackoverflow.com/questions/237804/user-defined-literals-in-c11-a-much-needed-addition-or-making-c-even-more-b">link</a>)<br />
<br /><span style="font-size: x-small;"><span style="color: #20124d;">template<char... bits=""> struct __checkbits</char...></span><br style="color: #20124d;" /><span style="color: #20124d;">{</span><br style="color: #20124d;" /><span style="color: #20124d;"> static const bool valid = false;</span><br style="color: #20124d;" /><span style="color: #20124d;">};</span><br style="color: #20124d;" /><br style="color: #20124d;" /><span style="color: #20124d;">template<char bits="" char...="" high,=""> struct __checkbits<high, bits...=""></high,></char></span><br style="color: #20124d;" /><span style="color: #20124d;">{</span><br style="color: #20124d;" /><span style="color: #20124d;"> static const bool valid = (High == '0' || High == '1')</span><br style="color: #20124d;" /><span style="color: #20124d;"> && __checkbits<bits...>::valid;</bits...></span><br style="color: #20124d;" /><span style="color: #20124d;">};</span><br style="color: #20124d;" /><br style="color: #20124d;" /><span style="color: #20124d;">template<char high=""> struct __checkbits<high></high></char></span><br style="color: #20124d;" /><span style="color: #20124d;">{</span><br style="color: #20124d;" /><span style="color: #20124d;"> static const bool valid = (High == '0' || High == '1');</span><br style="color: #20124d;" /><span style="color: #20124d;">};</span><br /><br />template<char... bits=""><br /> inline constexpr std::bitset<sizeof...(bits)><br /> operator<span style="color: #b45f06;">"" </span>_bits() noexcept<br />{<br /> static_assert(__checkbits<bits...>::valid, <span style="color: #b45f06;">"invalid digit in binary string"</span>);<br /> return std::bitset<sizeof...(bits)>((char []){Bits..., '\0'});<br />}<br /><br />int main()<br />{<br /> <b><span style="color: #274e13;">auto bits = 010101010101010101010101010101010101010101_bits;</span></b><br /> std::cout << bits << std::endl;<br /> std::cout << <span style="color: #b45f06;">"size = " </span><< bits.size() << std::endl;<br /> std::cout << <span style="color: #b45f06;">"count = "</span> << bits.count() << std::endl;<br /> std::cout << <span style="color: #b45f06;">"value = "</span> << bits.to_ullong() << std::endl;<br /><br /> // This triggers the static_assert at compile time.<br /> <b><span style="color: #274e13;">auto badbits = 21010101010101010101010101010101010101_bits;</span></b><br style="color: #274e13;" /><br /> // This throws at run time.<br /> <b><span style="color: #274e13;">std::bitset<64> badbits2("21010101010101010101010110101010101_bits");</span></b><br />}</sizeof...(bits)></bits...></sizeof...(bits)></char...></span><br /><br /><br />-ss<br /></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-83040161077955731272011-11-22T09:40:00.001-08:002011-11-22T09:51:05.704-08:00GCC 4.7.0: transactional memory<div dir="ltr" style="text-align: left;" trbidi="on">
Eventually GCC 4.7.0 will have transactional memory, which has been<br />
merged several days ago. Draft of still-in-progress design document can<br />
be found <a href="http://gcc.gnu.org/wiki/TransactionalMemory?action=AttachFile&do=view&target=C%2B%2B-transactional-constructs-1.0.pdf">here</a>.<br />
<br />
In short, (atomic) transaction is something similar to this:
<br />
<br />
<pre> __transaction_atomic { x++; }</pre>
<pre>
</pre>
Any operation performed within the <tt>__transaction_atomic</tt> block will be atomic and<br />
isolated from other transactions, operations within __transaction {} either be
visible to other threads in its entirety or not at all.<br />
<br />
Quote from <a href="http://lwn.net/Articles/466513/">lwn</a><br />
<div style="color: #0c343d;">
<span style="font-size: x-small;">Details on the specific implementation are scarce; it appears that, in the
current patch set,</span><br />
<span style="font-size: x-small;">transactions will be implemented using a global lock.
GCC developers debated for a bit over</span><br />
<span style="font-size: x-small;">whether this code was ready for
merging or not. In the end, though, the possibility of being</span><br />
<span style="font-size: x-small;">the first to
support an interesting new feature seemed to win out. Current plans are to</span><br />
<span style="font-size: x-small;">release 4.7.0 sometime around next April.</span></div>
<div style="color: #0c343d;">
</div>
<div style="color: #0c343d;">
<br /></div>
<div style="color: #0c343d;">
<span style="color: black; font-size: small;">Refer to <a href="http://gcc.gnu.org/wiki/TransactionalMemory">gcc.gnu.org</a> (or gcc 4.7 svn repository) for details.</span></div>
</div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-53254294797538843742011-11-15T10:51:00.001-08:002011-11-15T11:05:39.335-08:00Prettiness of git hooks<div dir="ltr" style="text-align: left;" trbidi="on">
Haven't blogged for a while, so just to keep this blog alive, some easy reading.<br />
Recently due to project needs we had to organize external .git repository mirror for <br />
code drops. The below notes probably will not discover anything new to you, though<br />
still may be interesting. Just in case.<br />
<br />
Well, to start with, we have several developer's trees and one master tree (obviously<br />
for merging, pushing and keeping stuff(<span style="font-size: xx-small;">tm</span>)). We also have to perform regular code drops<br />
(say, several times a week) with .git directory included. The usual solution could be<br />
just to perform `<b>clone</b>, <b>pull</b>, <b>pull</b>,...' on the remote machine, which, however, didn't<br />
work for us because of some company policies.<br />
<br />
So I performed trivial <b>scp</b> of cloned master tree to the remote machine (which is possibly<br />
not the best thing to do, but I didn't feel like doing all that <b>git init</b>, <b>scp files</b>, <br />
<b>git add</b>, <b>git commit</b> with <span style="font-size: x-small;"><span style="color: #134f5c;">"Initial commit"</span></span> message, etc.), and cleaned up .git/config.<br />
<br />
For <b>scp</b>-ed repo we should perform:<br />
<b style="color: #073763;">git config --bool core.bare true</b><br />
otherwise an attempt to push will make <b>git</b> suspicious that you may accidentally screw<br />
things up:<br />
<span style="background-color: #444444; font-size: x-small;"><span style="background-color: white; color: #444444;">remote: error: refusing to update checked out branch: refs/heads/master</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: By default, updating the current branch in a non-bare repository</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: is denied, because it will make the index and work tree inconsistent</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: with what you pushed, and will require 'git reset --hard' to match</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: the work tree to HEAD.</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error:</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: You can set 'receive.denyCurrentBranch' configuration variable to</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: its current branch; however, this is not recommended unless you</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: arranged to update its work tree to match what you pushed in some</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: other way.</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error:</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: To squelch this message and still keep the default behaviour, set</span><br style="background-color: white; color: #444444;" /><span style="background-color: white; color: #444444;">remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.</span></span><br />
<br />
The thing is that on the remote side we have to create <b>--tag</b> each time we perform<br />
a code drop. And this is kind of error prone because it's so easy just to forget<br />
perform <b>git tag</b>..., <b>git push --tags</b>.<br />
<br />
So I created an alias for tagging on the remote machine<br />
<br />
<b>.git/config</b><br />
<span style="font-size: x-small;"><span style="color: #783f04;">[alias]</span><br style="color: #783f04;" /><span style="color: #783f04;"> datetag = !git tag "project_name_"`date +%Y%m%d%H%M`</span></span><br />
<br />
(or perhaps time zone aware one via <span style="color: #783f04; font-size: x-small;">`TZ='REGION/CITY' date +%Y%m%d%H%M`</span>).<br />
<br />
<br />
The next thing was tagging automation. Which was simply achieved by<br />
git hooks (<a href="http://book.git-scm.com/5_git_hooks.html">git book</a>). There are lots of them (you can find examples within<br />
<span style="color: #444444; font-size: x-small;">.git/hooks/</span> directory). In order to enable hook, just remove .sample at the end<br />
of file name.<br />
<br />
The ideal candidate was:<br />
<span style="color: #0b5394; font-size: x-small;"><b>post-receive</b><br />GIT_DIR/hooks/post-receive<br />This hook is invoked by 'git-receive-pack' on the remote repository, which happens when a<br />'git-push' is done on a local repository. It executes on the remote repository once after<br />all the refs have been updated.</span><br />
<br />
<br />
With somewhat trivial implementation:<br />
<b>.git/hooks/post-receive</b><br />
<span style="color: #783f04; font-size: x-small;">#!/bin/sh<br />#<br /># To enable this hook, rename this file to "post-update".<br /><br />exec git datetag</span><br />
<br />
<br />
<br />
Since hooks are shell scripts it's really almost up to you to decide<br />
the level of `complexity' and `sophistication'.<br />
<br />
<br />
On the local host I created addition 'remote' config<br />
<b>.git/config</b><br />
<span style="color: #783f04; font-size: x-small;">[remote "drop"]<br /> url = git@remote_host_name:/project_repository_path</span><br />
<br />
and set appropriate ssh <b>IdentityFile</b> for <b>Host</b> in <b>~/.ssh/config</b> file.<br />
<br />
So now I can perform<br />
1) <b>git push</b><br />
for pushing to local master<br />
<br />
2) <b>git push drop</b><br />
for pushing and tagging to the remote host<br />
<br />
<br />
That's it, <b>git</b> is really awesome.<br />
<br />
-ss</div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-86423443037717609442011-10-23T15:18:00.000-07:002011-10-23T15:18:15.100-07:00Robot KHR3HV Rides Bike<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/SqBw7XapJKk?feature=player_embedded' frameborder='0'></iframe></div><br />
</div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-45329497518107671062011-10-15T04:23:00.000-07:002011-10-15T04:23:24.958-07:00Bits of History<div dir="ltr" style="text-align: left;" trbidi="on"><a href="http://www.gotw.ca/publications/c_family_interview.htm">The C Family of Languages: Interview with Dennis Ritchie, Bjarne Stroustrup, and James Gosling</a><br />
<br />
<span style="font-family: Arial,Arial,Helvetica; font-size: x-small;"><i><span style="color: teal;">This article appeared in <b>Java Report, 5(7), July 2000</b> and <b>C++ Report, 12(7), July/August 2000</b>.</span></i></span><br />
<span style="font-family: Arial,Arial,Helvetica; font-size: x-small;"><i><span style="color: teal;">VIa gotw.ca</span></i></span></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0tag:blogger.com,1999:blog-2220357220638464209.post-36401062176247225662011-10-13T02:58:00.000-07:002011-10-13T02:58:59.334-07:00Thank you Dennis<div dir="ltr" style="text-align: left;" trbidi="on"><b>Dennis MacAlistair Ritchie</b><br />
September 8, 1941 — October 8/9, 2011<br />
<span style="font-size: small;"><br />
</span><br />
<div style="color: #666666;"><i><span style="font-size: small;">" ... was an American computer scientist notable for developing C and </span></i></div><div style="color: #666666;"><i><span style="font-size: small;">for having influence on other programming languages, as well as operating</span></i></div><div style="color: #666666;"><i><span style="font-size: small;">systems such as Multics and Unix... "</span></i></div><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://upload.wikimedia.org/wikipedia/commons/thumb/0/01/Dennis_MacAlistair_Ritchie_.jpg/225px-Dennis_MacAlistair_Ritchie_.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://upload.wikimedia.org/wikipedia/commons/thumb/0/01/Dennis_MacAlistair_Ritchie_.jpg/225px-Dennis_MacAlistair_Ritchie_.jpg" /></a></div><br />
<br />
<br />
<span style="font-size: x-small;"><i>Image and text via wikipedia</i></span></div>Anonymoushttp://www.blogger.com/profile/05701404721438980585noreply@blogger.com0