본문 바로가기

Core BSP 분석/리눅스 커널 핵심 분석

[리눅스] printk 아규먼트 포멧

printk에 %로 어떤 형식을 지정할 지 헷갈릴 때가 많습니다.
이럴 때는 다음 형식을 참고하면 됩니다.
If variable is of Type, use printk format specifier:
------------------------------------------------------------
int %d or %x
unsigned int %u or %x
long %ld or %lx
unsigned long %lu or %lx
long long %lld or %llx
unsigned long long %llu or %llx
size_t %zu or %zx
ssize_t %zd or %zx
s32 %d or %x
u32 %u or %x
s64 %lld or %llx
u64 %llu or %llx
 
 
예를 들면 다음 코드와 같이,
timer->expires 멤버 변수를 (unsigned long long) 타입으로 캐스팅해서 %llu 형식으로 출력합니다.
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1008,6 +1010,21 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
  debug_activate(timer, expires);
  timer->expires = expires;
+
+ if (raspbian_debug_state == 5060) {
+ void *stack = NULL;
+ struct thread_info *current_thread;
+
+ stack = current->stack;
+ current_thread = (struct thread_info*)stack;
+
+ trace_printk("[-][%s]jiffies_64: %llu, timer->expires: %llu  caller:%pS \n",
+ current->comm, jiffies_64, (unsigned long long)timer->expires, (void *)__builtin_return_address(0));
+
+ trace_printk("[-] in_softirq(): 0x%08x,preempt_count = 0x%08x \n",
+ (unsigned int)in_softirq(), (unsigned int)current_thread->preempt_count);
+ }
 
출처