|
43 | 43 | #include <nuttx/mm/iob.h> |
44 | 44 | #include <nuttx/fs/fs.h> |
45 | 45 | #include <nuttx/fs/procfs.h> |
| 46 | +#include <nuttx/spinlock.h> |
46 | 47 |
|
47 | 48 | #include "fs_heap.h" |
48 | 49 |
|
@@ -111,6 +112,11 @@ const struct procfs_operations g_iobinfo_operations = |
111 | 112 | iobinfo_stat /* stat */ |
112 | 113 | }; |
113 | 114 |
|
| 115 | +#ifdef CONFIG_IOB_OWNER_TRACKING |
| 116 | +extern volatile spinlock_t g_iob_lock; |
| 117 | +extern FAR struct iob_s *g_iob_committed; |
| 118 | +#endif |
| 119 | + |
114 | 120 | /**************************************************************************** |
115 | 121 | * Private Functions |
116 | 122 | ****************************************************************************/ |
@@ -223,6 +229,44 @@ static ssize_t iobinfo_read(FAR struct file *filep, FAR char *buffer, |
223 | 229 | &offset); |
224 | 230 | totalsize += copysize; |
225 | 231 |
|
| 232 | +#ifdef CONFIG_IOB_OWNER_TRACKING |
| 233 | + buffer += copysize; |
| 234 | + buflen -= copysize; |
| 235 | + |
| 236 | + irqstate_t flags = spin_lock_irqsave(&g_iob_lock); |
| 237 | + |
| 238 | + for (unsigned int i = 0; i < CONFIG_IOB_NBUFFERS; i++) |
| 239 | + { |
| 240 | + FAR struct iob_s *iob = iob_get_iob_by_index(i); |
| 241 | + |
| 242 | + /* Print: PID (or -1 for ISR) and flags in hex */ |
| 243 | + |
| 244 | + if (iob->io_owner_flags != 0) |
| 245 | + { |
| 246 | + linesize = procfs_snprintf(iobfile->line, IOBINFO_LINELEN, |
| 247 | + "%02d %p -> %p pid=%d flags=0x%02x\n", i, |
| 248 | + iob, iob->io_flink, |
| 249 | + (int)iob->io_owner_pid, |
| 250 | + (unsigned)iob->io_owner_flags); |
| 251 | + } |
| 252 | + else |
| 253 | + { |
| 254 | + linesize = procfs_snprintf(iobfile->line, IOBINFO_LINELEN, |
| 255 | + "%02d %p -> %p Free\n", i, |
| 256 | + iob, iob->io_flink); |
| 257 | + } |
| 258 | + |
| 259 | + copysize = procfs_memcpy(iobfile->line, linesize, |
| 260 | + buffer, buflen, &offset); |
| 261 | + totalsize += copysize; |
| 262 | + |
| 263 | + buffer += copysize; |
| 264 | + buflen -= copysize; |
| 265 | + } |
| 266 | + |
| 267 | + spin_unlock_irqrestore(&g_iob_lock, flags); |
| 268 | +#endif |
| 269 | + |
226 | 270 | /* Update the file offset */ |
227 | 271 |
|
228 | 272 | filep->f_pos += totalsize; |
|
0 commit comments