/usr/share/systemtap/tapset/linux/task.stp is in systemtap-common 2.6-0.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | // task information tapset
// Copyright (C) 2006 Intel Corporation.
// Copyright (C) 2010-2014 Red Hat Inc.
//
// This file is part of systemtap, and is free software. You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.
%{
#include <linux/version.h>
#include <linux/file.h>
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)
#include <linux/fdtable.h>
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0)
#include <linux/sched/rt.h>
#endif
#ifndef STAPCONF_TASK_UID
#include <linux/cred.h>
#endif
%}
/**
* sfunction task_current - The current task_struct of the current task
*
* Description: This function returns the task_struct representing the current process.
* This address can be passed to the various task_*() functions to extract
* more task-specific data.
*/
function task_current:long () %{ /* pure */
STAP_RETVALUE = (unsigned long)current;
%}
function _task_rlimit_cur:long (task:long, nd_limit:long)
{
if (nd_limit < 0 || nd_limit >= %{ RLIM_NLIMITS %}) {
return -1;
}
sig = @cast(task, "task_struct", "kernel<linux/sched.h>")->signal;
return sig->rlim[nd_limit]->rlim_cur;
}
/* sfunction task_rlimit - The current resource limit of the task
*
* @task: task_struct pointer
* @lim_str: String representing limit.
*
* Description: Little bit slower way how ger resource limits of
* process.
* There is need translate string into number for each call.
*/
function task_rlimit:long (task:long, lim_str:string)
{
lim = rlimit_from_str(lim_str);
if (lim == -1) { return -1; }
return _task_rlimit_cur(task, lim);
}
/* Fast and "safe" way how to do it. */
function task_rlimit_cpu:long (task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_CPU %} );
}
function task_rlimit_fsize:long (task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_FSIZE %});
}
function task_rlimit_data:long (task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_DATA %});
}
function task_rlimit_stack:long (task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_STACK %});
}
function task_rlimit_core:long (task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_CORE %});
}
function task_rlimit_rss:long (task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_RSS %});
}
function task_rlimit_nproc:long (task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_NPROC %});
}
function task_rlimit_nofile:long(task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_NOFILE %});
}
function task_rlimit_memlock:long(task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_MEMLOCK %});
}
function task_rlimit_as:long(task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_AS %});
}
function task_rlimit_locks:long(task:long)
{
return _task_rlimit_cur(task, %{ RLIMIT_LOCKS %});
}
function task_rlimit_sigpending:long(task:long)
{
%( kernel_v >= "2.6.8" %?
return _task_rlimit_cur(task, %{ RLIMIT_SIGPENDING %});
%:
return -1
%)
}
function task_rlimit_msgqueue:long(task:long)
{
%( kernel_v >= "2.6.8" %?
return _task_rlimit_cur(task, %{ RLIMIT_MSGQUEUE %});
%:
return -1
%)
}
function task_rlimit_nice:long(task:long)
{
%( kernel_v >= "2.6.12" %?
return _task_rlimit_cur(task, %{ RLIMIT_NICE %});
%:
return -1
%)
}
function task_rlimit_rtprio:long(task:long)
{
%( kernel_v >= "2.6.12" %?
return _task_rlimit_cur(task, %{ RLIMIT_RTPRIO %});
%:
return -1
%)
}
function task_rlimit_rttime:long(task:long)
{
%( kernel_v >= "2.6.25" %?
return _task_rlimit_cur(task, %{ RLIMIT_RTTIME %});
%:
return -1
%)
}
/**
* sfunction task_parent - The task_struct of the parent task
*
* @task: task_struct pointer
*
* Description: This function returns the parent task_struct of
* the given task. This address can be passed to the various
* task_*() functions to extract more task-specific data.
*/
function task_parent:long(task:long)
{
return @choose_defined(
@cast(task, "task_struct", "kernel<linux/sched.h>")->real_parent,
@cast(task, "task_struct", "kernel<linux/sched.h>")->parent)
}
/**
* sfunction task_state - The state of the task
*
* @task: task_struct pointer
*
* Description: Return the state of the given task, one of:
* TASK_RUNNING (0), TASK_INTERRUPTIBLE (1), TASK_UNINTERRUPTIBLE (2),
* TASK_STOPPED (4), TASK_TRACED (8), EXIT_ZOMBIE (16), or EXIT_DEAD (32).
*/
function task_state:long (task:long)
{
return @cast(task, "task_struct", "kernel<linux/sched.h>")->state
}
/**
* sfunction task_execname - The name of the task
*
* @task: task_struct pointer
*
* Description: Return the name of the given task.
*/
function task_execname:string (task:long)
{
return kernel_string(@cast(task, "task_struct", "kernel<linux/sched.h>")->comm)
}
/**
* sfunction task_pid - The process identifier of the task
*
* @task: task_struct pointer
*
* Description: This fucntion returns the process id of the given task.
*/
function task_pid:long (task:long)
{
return @cast(task, "task_struct", "kernel<linux/sched.h>")->tgid
}
/**
* sfunction pid2task - The task_struct of the given process identifier
*
* @pid: process identifier
*
* Description: Return the task struct of the given process id.
*/
function pid2task:long (pid:long) %{ /* pure */
struct task_struct *t = NULL;
pid_t t_pid = (pid_t)(long)STAP_ARG_pid;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
struct pid *p_pid = find_get_pid(t_pid);
rcu_read_lock();
t = pid_task(p_pid, PIDTYPE_PID);
put_pid(p_pid);
#else
rcu_read_lock();
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
t = find_task_by_vpid (t_pid);
#else
t = find_task_by_pid (t_pid);
#endif /* 2.6.24 */
#endif /* 2.6.31 */
rcu_read_unlock();
STAP_RETVALUE = (unsigned long)t;
%}
/**
* sfunction pid2execname - The name of the given process identifier
*
* @pid: process identifier
*
* Description: Return the name of the given process id.
*/
function pid2execname:string (pid:long) {
tsk = pid2task(pid)
if (tsk)
return task_execname(tsk)
return ""
}
/**
* sfunction task_tid - The thread identifier of the task
*
* @task: task_struct pointer
*
* Description: This function returns the thread id of the given task.
*/
function task_tid:long (task:long)
{
return @cast(task, "task_struct", "kernel<linux/sched.h>")->pid
}
/**
* sfunction task_gid - The group identifier of the task
*
* @task: task_struct pointer
*
* Description: This function returns the group id of the given task.
*/
function task_gid:long (task:long) %{ /* pure */
struct task_struct *t = (struct task_struct *)(long)STAP_ARG_task;
#ifdef STAPCONF_TASK_UID
STAP_RETVALUE = kread(&(t->gid));
CATCH_DEREF_FAULT();
#else
/* If task_gid() isn't defined, make our own. */
#if !defined(task_gid) && defined(task_cred_xxx)
#define task_gid(task) (task_cred_xxx((task), gid))
#endif
/* XXX: We can't easily kread this rcu-protected field. */
#if defined(CONFIG_USER_NS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
STAP_RETVALUE = from_kgid_munged(task_cred_xxx(t, user_ns), task_gid(t));
#else
STAP_RETVALUE = task_gid (t);
#endif
#endif
%}
/**
* sfunction task_egid - The effective group identifier of the task
*
* @task: task_struct pointer
*
* Description: This function returns the effective group id of the given task.
*/
function task_egid:long (task:long) %{ /* pure */
struct task_struct *t = (struct task_struct *)(long)STAP_ARG_task;
#ifdef STAPCONF_TASK_UID
STAP_RETVALUE = kread(&(t->egid));
CATCH_DEREF_FAULT();
#else
/* If task_egid() isn't defined, make our own. */
#if !defined(task_egid) && defined(task_cred_xxx)
#define task_egid(task) (task_cred_xxx((task), egid))
#endif
/* XXX: We can't easily kread this rcu-protected field. */
#if defined(CONFIG_USER_NS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
STAP_RETVALUE = from_kgid_munged(task_cred_xxx(t, user_ns), task_egid(t));
#else
STAP_RETVALUE = task_egid (t);
#endif
#endif
%}
/**
* sfunction task_uid - The user identifier of the task
*
* @task: task_struct pointer
*
* Description: This function returns the user id of the given task.
*/
function task_uid:long (task:long) %{ /* pure */
struct task_struct *t = (struct task_struct *)(long)STAP_ARG_task;
#ifdef STAPCONF_TASK_UID
STAP_RETVALUE = kread(&(t->uid));
CATCH_DEREF_FAULT();
#else
/* XXX: We can't easily kread this rcu-protected field. */
#if defined(CONFIG_USER_NS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
STAP_RETVALUE = from_kuid_munged(task_cred_xxx(t, user_ns), task_uid(t));
#else
STAP_RETVALUE = task_uid (t);
#endif
#endif
%}
/**
* sfunction task_euid - The effective user identifier of the task
*
* @task: task_struct pointer
*
* Description: This function returns the effective user id of the given task.
*/
function task_euid:long (task:long) %{ /* pure */
struct task_struct *t = (struct task_struct *)(long)STAP_ARG_task;
#ifdef STAPCONF_TASK_UID
STAP_RETVALUE = kread(&(t->euid));
CATCH_DEREF_FAULT();
#else
/* XXX: We can't easily kread this rcu-protected field. */
#if defined(CONFIG_USER_NS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0))
STAP_RETVALUE = from_kuid_munged(task_cred_xxx(t, user_ns), task_euid(t));
#else
STAP_RETVALUE = task_euid (t);
#endif
#endif
%}
/**
* sfunction task_prio - The priority value of the task
*
* @task: task_struct pointer
*
* Description: This function returns the priority value of the given task.
*/
function task_prio:long (task:long) %{ /* pure */
struct task_struct *t = (struct task_struct *)(long)STAP_ARG_task;
STAP_RETVALUE = kread(&(t->prio)) - MAX_RT_PRIO;
CATCH_DEREF_FAULT();
%}
/**
* sfunction task_nice - The nice value of the task
*
* @task: task_struct pointer
*
* Description: This function returns the nice value of the given task.
*/
function task_nice:long (task:long) %{ /* pure */
struct task_struct *t = (struct task_struct *)(long)STAP_ARG_task;
STAP_RETVALUE = kread(&(t->static_prio)) - MAX_RT_PRIO - 20;
CATCH_DEREF_FAULT();
%}
/**
* sfunction task_cpu - The scheduled cpu of the task
*
* @task: task_struct pointer
*
* Description: This function returns the scheduled cpu for the given task.
*/
function task_cpu:long (task:long)
{
ti = @choose_defined(@cast(task, "task_struct", "kernel<linux/sched.h>")->stack,
@cast(task, "task_struct", "kernel<linux/sched.h>")->thread_info);
return @cast(ti, "thread_info", "kernel<linux/sched.h>")->cpu
}
/**
* sfunction task_open_file_handles - The number of open files of the task
*
* @task: task_struct pointer
*
* Description: This function returns the number of open file handlers for the given task.
*/
function task_open_file_handles:long (task:long)
%{ /* pure */
int locked = 0;
unsigned int count=0, fd, max;
struct task_struct *t;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
/* Older kernels */
struct files_struct *f;
#else
struct files_struct *fs;
struct fdtable *f;
#endif
t = (struct task_struct *)(long)STAP_ARG_task;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
/* Older kernels */
f = kread(&(t->files));
#else
fs = kread(&(t->files));
f = kread(&(fs->fdt));
#endif
rcu_read_lock();
locked = 1;
max = kread(&(f->max_fds));
for (fd = 0; fd < max; fd++) {
if ( kread(&(f->fd[fd])) != NULL)
count ++;
}
STAP_RETVALUE = count;
CATCH_DEREF_FAULT();
if (locked)
rcu_read_unlock();
%}
/**
* sfunction task_max_file_handles - The max number of open files for the task
*
* @task: task_struct pointer
*
* Description: This function returns the maximum number of file handlers for the given task.
*/
function task_max_file_handles:long (task:long)
%{ /* pure */
int locked = 0;
struct task_struct *t;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
struct files_struct *f;
#else
struct files_struct *fs;
struct fdtable *f;
#endif
t = (struct task_struct *)(long)STAP_ARG_task;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
f = kread(&(t->files));
#else
fs = kread (&(t->files));
f = kread(&(fs->fdt));
#endif
rcu_read_lock();
locked = 1;
STAP_RETVALUE = kread(&(f->max_fds));
CATCH_DEREF_FAULT();
if (locked)
rcu_read_unlock();
%}
|