Put a small apple script into your crontab which will look in the System Events log and tell iChat to login if it sees the disconnect event in there.
In a terminal:
crontab -e
*/5 * * * * osascript -e 'tell application "System Events" to if (processes whose name is "iChat") exists then tell application "iChat" to log in'
This blog serves as a dumping ground for my own interests. On it you will find anything which I want to keep track of; links, articles, tips and tricks. Mostly it focuses on C++, Javascript and HTML, linux and performance.
Wednesday, 18 April 2012
Tuesday, 17 April 2012
(Functional) Reactive Programming in C++
The introduction to Reactive Programming you've been missing
https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
The canonical stackoverflow question
http://stackoverflow.com/questions/1028250/what-is-functional-reactive-programming
What is Reactive Programming?
http://www.paulstovell.com/reactive-programming
FRP in C++ and Its Application
ftp://netlib.bell-labs.com/who/Old/blume/icfp02/191.pdf
C++ implementation: C++ Rx library
https://github.com/Reactive-Extensions/RxCpp
https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
The canonical stackoverflow question
http://stackoverflow.com/questions/1028250/what-is-functional-reactive-programming
What is Reactive Programming?
http://www.paulstovell.com/reactive-programming
FRP in C++ and Its Application
ftp://netlib.bell-labs.com/who/Old/blume/icfp02/191.pdf
C++ implementation: C++ Rx library
https://github.com/Reactive-Extensions/RxCpp
Thursday, 12 April 2012
Kenel bypass & zero-copy
http://ttthebear.blogspot.com/2008/07/linux-kernel-bypass-and-performance.html
kernel bypass
http://www.networkworld.com/news/tech/2005/013105techupdate.html
zero-copy
http://lwn.net/2001/0419/kernel.php3http://www.linuxjournal.com/article/6345
Interrupt Coalescence
It is possible to reduce mean latency, but will most likely increase the min latency
RDMA
http://www.networkworld.com/news/tech/2003/0324tech.html
http://www.networkworld.com/newsletters/lans/2002/01556276.html
Request completions might be processed either entirely in user space (by polling a user-level completion queue) or through the kernel in cases where the application wishes to sleep until a completion occurs.
A Fast Read/Write Process to Reduce RDMA Communication Latencyhttp://www.people.vcu.edu/~xhe2/publications/Conferences/FRRWP_NAS06.pdf
--- implementation of user-space waiting on rdma ---
create a condition variable based on a futex
have rdma completion handler wake the condition variable
kernel bypass
http://www.networkworld.com/news/tech/2005/013105techupdate.html
zero-copy
http://lwn.net/2001/0419/kernel.php3http://www.linuxjournal.com/article/6345
Interrupt Coalescence
It is possible to reduce mean latency, but will most likely increase the min latency
RDMA
http://www.networkworld.com/news/tech/2003/0324tech.html
http://www.networkworld.com/newsletters/lans/2002/01556276.html
Request completions might be processed either entirely in user space (by polling a user-level completion queue) or through the kernel in cases where the application wishes to sleep until a completion occurs.
A Fast Read/Write Process to Reduce RDMA Communication Latencyhttp://www.people.vcu.edu/~xhe2/publications/Conferences/FRRWP_NAS06.pdf
--- implementation of user-space waiting on rdma ---
create a condition variable based on a futex
have rdma completion handler wake the condition variable
c++11 reference implementation for std::min and std::max
Prepare to have your mind boggled!
This is a reference implementation for std::min and std::max, using c++11 features
namespace detail
{
template <class T, bool make_const, bool make_volatile>
struct union_cv_helper;
template <class T>
struct union_cv_helper<T, false, false>
{
typedef T type;
};
template <class T>
struct union_cv_helper<T, false, true>
{
typedef volatile T type;
};
template <class T>
struct union_cv_helper<T, true, false>
{
typedef const T type;
};
template <class T>
struct union_cv_helper<T, true, true>
{
typedef const volatile T type;
};
} // detail
template <class T, class U>
struct union_cv
{
static const bool make_const = std::tr1::is_const<T>::value || std::tr1::is_const<U>::value;
static const bool make_volatile = std::tr1::is_volatile<T>::value || std::tr1::is_volatile<U>::value;
typedef typename std::tr1::remove_cv<T>::type Tr;
typedef typename std::tr1::remove_cv<U>::type Ur;
typedef typename detail::union_cv_helper<Tr, make_const, make_volatile>::type type;
};
template <class T, class U>
struct promote
{
static T t;
static U u;
static bool b;
typedef typename std::tr1::remove_cv<decltype(b ? t : u)>::type type;
};
namespace detail
{
template <class T, class Tr, class U, class Ur>
struct min_max_return_helper
{
typedef typename promote<T&, U&>::type type;
};
template <class T, class Tr, class U>
struct min_max_return_helper<T, Tr, U, Tr>
{
typedef typename union_cv<T, U>::type& type;
};
template <class T, T t, class U, U u>
struct safe_less_equal
{
static const bool Tsigned = std::tr1::is_signed<T>::value;
static const bool Usigned = std::tr1::is_signed<U>::value;
static const bool Tneg = Tsigned && t < T(0);
static const bool Uneg = Usigned && u < U(0);
static const bool value = Tneg == Uneg ? t <= u : Tneg;
};
template <class T>
struct int_min
{
static const T value = std::tr1::is_signed<T>::value ? T(T(1) << std::numeric_limits<T>::digits) : T(0);
};
template <class T>
struct int_max
{
static const T value = T(~int_min<T>::value);
};
template <class T, class U, bool = std::tr1::is_integral<T>::value && std::tr1::is_integral<U>::value>
struct safe_compare_imp
{
typedef typename promote<T, U>::type R;
static const R Rmin = int_min<R>::value;
static const R Rmax = int_max<R>::value;
static const T Tmin = int_min<T>::value;
static const T Tmax = int_max<T>::value;
static const U Umin = int_min<U>::value;
static const U Umax = int_max<U>::value;
static const bool value = safe_less_equal<R, Rmin, T, Tmin>::value &&
safe_less_equal<R, Rmin, U, Umin>::value &&
safe_less_equal<T, Tmax, R, Rmax>::value &&
safe_less_equal<U, Umax, R, Rmax>::value;
};
template <class T, class U>
struct safe_compare_imp<T, U, false>
{
static const bool value = true;
};
template <class T>
struct safe_compare_imp<T, T, true>
{
static const bool value = true;
};
template <class T>
struct safe_compare_imp<T, T, false>
{
static const bool value = true;
};
template <class T, class U>
struct safe_compare
{
private:
typedef typename std::tr1::remove_cv<typename std::tr1::remove_reference<T>::type>::type Tr;
typedef typename std::tr1::remove_cv<typename std::tr1::remove_reference<U>::type>::type Ur;
public:
static const bool value = detail::safe_compare_imp<Tr, Ur>::value;
};
} // detail
template <class T, class U, bool = detail::safe_compare<T, U>::value>
struct min_max_return {};
template <class T, class U>
struct min_max_return<T&&, U&&, true>
{
typedef typename promote<T&&, U&&>::type type;
};
template <class T, class U>
struct min_max_return<T&&, U&, true>
{
typedef typename promote<T&&, U&>::type type;
};
template <class T, class U>
struct min_max_return<T&, U&&, true>
{
typedef typename promote<T&, U&&>::type type;
};
template <class T, class U>
struct min_max_return<T&, U&, true>
{
private:
typedef typename std::tr1::remove_cv<T>::type Tr;
typedef typename std::tr1::remove_cv<U>::type Ur;
public:
typedef typename detail::min_max_return_helper<T, Tr, U, Ur>::type type;
};
template <class T, class U>
inline
typename min_max_return<T&&, U&&>::type
min(T&& a, U&& b)
{
if (b < a)
return std::forward<U>(b);
return std::forward<T>(a);
}
template <class T, class U, class Compare>
inline
typename min_max_return<T&&, U&&>::type
min(T&& a, U&& b, Compare comp)
{
if (comp(b, a))
return std::forward<U>(b);
return std::forward<T>(a);
}
template <class T, class U>
inline
typename min_max_return<T&&, U&&>::type
max(T&& a, U&& b)
{
if (a < b)
return std::forward<U>(b);
return std::forward<T>(a);
}
template <class T, class U, class Compare>
inline
typename min_max_return<T&&, U&&>::type
max(T&& a, U&& b, Compare comp)
{
if (comp(a, b))
return std::forward<U>(b);
return std::forward<T>(a);
}
This is a reference implementation for std::min and std::max, using c++11 features
namespace detail
{
template <class T, bool make_const, bool make_volatile>
struct union_cv_helper;
template <class T>
struct union_cv_helper<T, false, false>
{
typedef T type;
};
template <class T>
struct union_cv_helper<T, false, true>
{
typedef volatile T type;
};
template <class T>
struct union_cv_helper<T, true, false>
{
typedef const T type;
};
template <class T>
struct union_cv_helper<T, true, true>
{
typedef const volatile T type;
};
} // detail
template <class T, class U>
struct union_cv
{
static const bool make_const = std::tr1::is_const<T>::value || std::tr1::is_const<U>::value;
static const bool make_volatile = std::tr1::is_volatile<T>::value || std::tr1::is_volatile<U>::value;
typedef typename std::tr1::remove_cv<T>::type Tr;
typedef typename std::tr1::remove_cv<U>::type Ur;
typedef typename detail::union_cv_helper<Tr, make_const, make_volatile>::type type;
};
template <class T, class U>
struct promote
{
static T t;
static U u;
static bool b;
typedef typename std::tr1::remove_cv<decltype(b ? t : u)>::type type;
};
namespace detail
{
template <class T, class Tr, class U, class Ur>
struct min_max_return_helper
{
typedef typename promote<T&, U&>::type type;
};
template <class T, class Tr, class U>
struct min_max_return_helper<T, Tr, U, Tr>
{
typedef typename union_cv<T, U>::type& type;
};
template <class T, T t, class U, U u>
struct safe_less_equal
{
static const bool Tsigned = std::tr1::is_signed<T>::value;
static const bool Usigned = std::tr1::is_signed<U>::value;
static const bool Tneg = Tsigned && t < T(0);
static const bool Uneg = Usigned && u < U(0);
static const bool value = Tneg == Uneg ? t <= u : Tneg;
};
template <class T>
struct int_min
{
static const T value = std::tr1::is_signed<T>::value ? T(T(1) << std::numeric_limits<T>::digits) : T(0);
};
template <class T>
struct int_max
{
static const T value = T(~int_min<T>::value);
};
template <class T, class U, bool = std::tr1::is_integral<T>::value && std::tr1::is_integral<U>::value>
struct safe_compare_imp
{
typedef typename promote<T, U>::type R;
static const R Rmin = int_min<R>::value;
static const R Rmax = int_max<R>::value;
static const T Tmin = int_min<T>::value;
static const T Tmax = int_max<T>::value;
static const U Umin = int_min<U>::value;
static const U Umax = int_max<U>::value;
static const bool value = safe_less_equal<R, Rmin, T, Tmin>::value &&
safe_less_equal<R, Rmin, U, Umin>::value &&
safe_less_equal<T, Tmax, R, Rmax>::value &&
safe_less_equal<U, Umax, R, Rmax>::value;
};
template <class T, class U>
struct safe_compare_imp<T, U, false>
{
static const bool value = true;
};
template <class T>
struct safe_compare_imp<T, T, true>
{
static const bool value = true;
};
template <class T>
struct safe_compare_imp<T, T, false>
{
static const bool value = true;
};
template <class T, class U>
struct safe_compare
{
private:
typedef typename std::tr1::remove_cv<typename std::tr1::remove_reference<T>::type>::type Tr;
typedef typename std::tr1::remove_cv<typename std::tr1::remove_reference<U>::type>::type Ur;
public:
static const bool value = detail::safe_compare_imp<Tr, Ur>::value;
};
} // detail
template <class T, class U, bool = detail::safe_compare<T, U>::value>
struct min_max_return {};
template <class T, class U>
struct min_max_return<T&&, U&&, true>
{
typedef typename promote<T&&, U&&>::type type;
};
template <class T, class U>
struct min_max_return<T&&, U&, true>
{
typedef typename promote<T&&, U&>::type type;
};
template <class T, class U>
struct min_max_return<T&, U&&, true>
{
typedef typename promote<T&, U&&>::type type;
};
template <class T, class U>
struct min_max_return<T&, U&, true>
{
private:
typedef typename std::tr1::remove_cv<T>::type Tr;
typedef typename std::tr1::remove_cv<U>::type Ur;
public:
typedef typename detail::min_max_return_helper<T, Tr, U, Ur>::type type;
};
template <class T, class U>
inline
typename min_max_return<T&&, U&&>::type
min(T&& a, U&& b)
{
if (b < a)
return std::forward<U>(b);
return std::forward<T>(a);
}
template <class T, class U, class Compare>
inline
typename min_max_return<T&&, U&&>::type
min(T&& a, U&& b, Compare comp)
{
if (comp(b, a))
return std::forward<U>(b);
return std::forward<T>(a);
}
template <class T, class U>
inline
typename min_max_return<T&&, U&&>::type
max(T&& a, U&& b)
{
if (a < b)
return std::forward<U>(b);
return std::forward<T>(a);
}
template <class T, class U, class Compare>
inline
typename min_max_return<T&&, U&&>::type
max(T&& a, U&& b, Compare comp)
{
if (comp(a, b))
return std::forward<U>(b);
return std::forward<T>(a);
}
Decrypting the CanYouCrackIt MOD puzzle
Awesome piece of hacking/deconstruction, including assembly deconstruction and a virtual machine implementation
http://gchqchallenge.blogspot.com/
Find cpuId current thread is running on
void get_cpu_id(uint32_t& cpu_id)
{
uint32_t leaf = 0x0B;
__asm__ __volatile__("cpuid" : "=d"(cpu_id) : "a"(leaf) : "%rbx", "%rcx");
}
{
uint32_t leaf = 0x0B;
__asm__ __volatile__("cpuid" : "=d"(cpu_id) : "a"(leaf) : "%rbx", "%rcx");
}
low latency kernel resources
Processor and thread affinity
http://www.kernel.org/doc/man-pages/online/pages/man2/sched_setaffinity.2.html
http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_attr_setaffinity_np.3.html
Scheduler priority and RT scheduling
http://www.kernel.org/doc/man-pages/online/pages/man2/sched_setscheduler.2.html
http://www.kernel.org/doc/man-pages/online/pages/man2/sched_get_priority_max.2.html
http://www.kernel.org/doc/man-pages/online/pages/man2/getrlimit.2.html
Memory page locking
http://www.kernel.org/doc/man-pages/online/pages/man2/mlock.2.html
http://www.kernel.org/doc/man-pages/online/pages/man7/cpuset.7.html
IRQ interrupt coalesscing and IRQ masking
http://www.kernel.org/doc/htmldocs/genericirq/
NUMA aware memory allocation resources
http://www.kernel.org/doc/man-pages/online/pages/man7/numa.7.html
http://www.kernel.org/doc/man-pages/online/pages/man2/set_mempolicy.2.html
http://linux.die.net/man/8/numactl
http://en.wikipedia.org/wiki/Non-Uniform_Memory_Access
http://www.kernel.org/doc/man-pages/online/pages/man7/cpuset.7.html
http://www.kernel.org/doc/man-pages/online/pages/man2/sched_setaffinity.2.html
http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_attr_setaffinity_np.3.html
Scheduler priority and RT scheduling
http://www.kernel.org/doc/man-pages/online/pages/man2/sched_setscheduler.2.html
http://www.kernel.org/doc/man-pages/online/pages/man2/sched_get_priority_max.2.html
http://www.kernel.org/doc/man-pages/online/pages/man2/getrlimit.2.html
Memory page locking
http://www.kernel.org/doc/man-pages/online/pages/man2/mlock.2.html
http://www.kernel.org/doc/man-pages/online/pages/man7/cpuset.7.html
IRQ interrupt coalesscing and IRQ masking
http://www.kernel.org/doc/htmldocs/genericirq/
NUMA aware memory allocation resources
http://www.kernel.org/doc/man-pages/online/pages/man7/numa.7.html
http://www.kernel.org/doc/man-pages/online/pages/man2/set_mempolicy.2.html
http://linux.die.net/man/8/numactl
http://en.wikipedia.org/wiki/Non-Uniform_Memory_Access
http://www.kernel.org/doc/man-pages/online/pages/man7/cpuset.7.html
isolcpus - isolate cpus from the kernel scheduler
isolcpus kernel configuration
isolate cpus from the kernel scheduler
useful for removing the critical cores from the scheduler - therefore pinned threads won't be preempted when they block on IO or similar, and therefore that core's data caches won't be trashed by other threads
http://www.linuxtopia.org/online_books/linux_kernel/kernel_configuration/re46.html
isolate cpus from the kernel scheduler
useful for removing the critical cores from the scheduler - therefore pinned threads won't be preempted when they block on IO or similar, and therefore that core's data caches won't be trashed by other threads
http://www.linuxtopia.org/online_books/linux_kernel/kernel_configuration/re46.html
Linux realtime performance articles
Drepper / Red Hat - “What every programmer should know about memory”
http://lwn.net/Articles/259710/
Duval / Red Hat - “From Fast to Predictably Fast”
http://kernel.org/doc/ols/2009/ols2009-pages-79-86.pdf
Lameter / Linux Foundation - “Shoot First and Stop the OS Noise”
http://kernel.org/doc/ols/2009/ols2009-pages-159-168.pdf
http://lwn.net/Articles/259710/
Duval / Red Hat - “From Fast to Predictably Fast”
http://kernel.org/doc/ols/2009/ols2009-pages-79-86.pdf
Lameter / Linux Foundation - “Shoot First and Stop the OS Noise”
http://kernel.org/doc/ols/2009/ols2009-pages-159-168.pdf
Subscribe to:
Posts (Atom)