+static inline int ppm_hash_pid(pid_t pid)
+{
+ return jhash_1word(pid, JHASH_RANDOM) & PPM_HASH_MASK;
+}
+
+static struct process_pid_map *find_ppm(pid_t pid)
+{
+ const int hash_idx = ppm_hash_pid(pid);
+ struct process_pid_map *ppm;
+
+ ppm = ppm_hash_table[hash_idx];
+ while (ppm) {
+ if (ppm->pid == pid)
+ return ppm;
+
+ ppm = ppm->hash_next;
+ }
+
+ return NULL;
+}
+
+static struct process_pid_map *add_ppm_hash(pid_t pid, const char *name)
+{
+ const int hash_idx = ppm_hash_pid(pid);
+ struct process_pid_map *ppm;
+
+ ppm = find_ppm(pid);
+ if (!ppm) {
+ ppm = malloc(sizeof(*ppm));
+ memset(ppm, 0, sizeof(*ppm));
+ ppm->pid = pid;
+ memset(ppm->comm, 0, sizeof(ppm->comm));
+ strncpy(ppm->comm, name, sizeof(ppm->comm));
+ ppm->comm[sizeof(ppm->comm) - 1] = '\0';
+ ppm->hash_next = ppm_hash_table[hash_idx];
+ ppm_hash_table[hash_idx] = ppm;
+ }
+
+ return ppm;
+}
+
+static void handle_notify(struct blk_io_trace *bit)
+{
+ void *payload = (caddr_t) bit + sizeof(*bit);
+ __u32 two32[2];
+
+ switch (bit->action) {
+ case BLK_TN_PROCESS:
+ add_ppm_hash(bit->pid, payload);
+ break;
+
+ case BLK_TN_TIMESTAMP:
+ if (bit->pdu_len != sizeof(two32))
+ return;
+ memcpy(two32, payload, sizeof(two32));
+ if (!data_is_native) {
+ two32[0] = be32_to_cpu(two32[0]);
+ two32[1] = be32_to_cpu(two32[1]);
+ }
+ start_timestamp = bit->time;
+ abs_start_time.tv_sec = two32[0];
+ abs_start_time.tv_nsec = two32[1];
+ if (abs_start_time.tv_nsec < 0) {
+ abs_start_time.tv_sec--;
+ abs_start_time.tv_nsec += 1000000000;
+ }
+
+ break;
+
+ case BLK_TN_MESSAGE:
+ if (bit->pdu_len > 0) {
+ char msg[bit->pdu_len+1];
+
+ memcpy(msg, (char *)payload, bit->pdu_len);
+ msg[bit->pdu_len] = '\0';
+
+ fprintf(ofp,
+ "%3d,%-3d %2d %8s %5d.%09lu %5u %2s %3s %s\n",
+ MAJOR(bit->device), MINOR(bit->device),
+ bit->cpu, "0", (int) SECONDS(bit->time),
+ (unsigned long) NANO_SECONDS(bit->time),
+ 0, "m", "N", msg);
+ }
+ break;
+
+ default:
+ /* Ignore unknown notify events */
+ ;
+ }
+}
+
+char *find_process_name(pid_t pid)
+{
+ struct process_pid_map *ppm = find_ppm(pid);
+
+ if (ppm)
+ return ppm->comm;
+
+ return NULL;
+}
+
+static inline int ppi_hash_pid(pid_t pid)