Skip to content

Instantly share code, notes, and snippets.

@heechul
heechul / kpc_demo.c
Created December 2, 2022 11:31 — forked from ibireme/kpc_demo.c
A demo shows how to read Intel or Apple M1 CPU performance counter in macOS.
// =============================================================================
// XNU kperf/kpc demo
// Available for 64-bit Intel/Apple Silicon, macOS/iOS, with root privileges
//
//
// Demo 1 (profile a function in current thread):
// 1. Open directory '/usr/share/kpep/', find your CPU PMC database.
// For M1 (Pro/Max), the database file is '/usr/share/kpep/a14.plist'.
// 2. Select a few events that you are interested in,
// add their names to the `profile_events` array below.
@heechul
heechul / inverted-qlearn.py
Created January 2, 2017 17:42
OpenAI CartPole-v0 solution based on Q-learning
'''
Based the following two code bases:
- Berkeley's CS188 pacman project code
http://ai.berkeley.edu/
- Victor Mayoral Vilches's RL tutorial
https://github.com/vmayoral/basic_reinforcement_learning
@author: Heechul Yun (heechul.yun@gmail.com)
'''
@heechul
heechul / patch-3.5.0-bvt1
Created December 10, 2015 16:30 — forked from leverich/patch-3.5.0-bvt1
Borrowed Virtual Time patch against Linux 3.5.0
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 4a1f493..ef258ef 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1179,6 +1179,10 @@ struct sched_entity {
u64 exec_start;
u64 sum_exec_runtime;
u64 vruntime;
+#ifdef CONFIG_CFS_BVT
+ u64 effective_vruntime;
$ ps -eo pri,nice,rtprio,pid,psr,comm | sort -n
PRI NI RTPRIO PID PSR COMMAND
14 5 - 31 3 ksmd
18 1 - 2301 0 rtkit-daemon
19 0 - 1001 1 upstart-socket-
19 0 - 1069 0 dbus-daemon
19 0 - 1092 2 bluetoothd
...
...
39 -20 - 782 2 iwlwifi
static inline void arch_spin_unlock(arch_spinlock_t *lock)
{
1: smp_mb();
__asm__ __volatile__(
2:" str %1, [%0]\n"
:
: "r" (&lock->lock), "r" (0)
: "cc");
3: dsb_sev();
static inline void arch_spin_lock(arch_spinlock_t *lock)
{
unsigned long tmp;
__asm__ __volatile__(
1: "1: ldrex %0, [%1]\n"
2: " teq %0, #0\n"
3: WFE("ne")
4: " strexeq %0, %2, [%1]\n"
5: " teqeq %0, #0\n"
6: " bne 1b"
struct irq_work {
unsigned long flags;
struct llist_node llnode;
void (*func)(struct irq_work *);
};
static inline
void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))
struct irq_work {
unsigned long flags;
struct llist_node llnode;
void (*func)(struct irq_work *);
};
static inline
void init_irq_work(struct irq_work *work, void (*func)(struct irq_work *))
@heechul
heechul / timer.c
Created April 25, 2012 14:15
timer resolution check user application
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#define USECREQ 250
#define LOOPS   1000