Unison Help

- Unison Kernel
- Pthreads
- pthread_create()
- pthread_exit()
- pthread_self()
- pthread_equal()
- pthread_join()
- pthread_detach()
- pthread_setschedparam()
- pthread_getschedparam()
- pthread_attr_init()
- pthread_attr_destroy()
- pthread_attr_setstackaddr()
- pthread_attr_getstackaddr()
- pthread_attr_setstacksize()
- pthread_attr_getstacksize()
- pthread_attr_setschedparam()
- pthread_attr_getschedparam()
- pthread_attr_setdetachstate()
- pthread_attr_getdetachstate()
- pthread_stackinfo()
- pthread_setprio()
- pthread_getprio()
- sched_get_priority_max()
- sched_get_priority_min()
- sched_yield()
- Pthread Cancellation
- Mutex
- Semaphores
- Message Queues
- Conditional Variables
- Barriers
- Timers
- Clocks
- Memory Allocation
- Rendezvous
- Interrupts
- Directory Services
- Miscellaneous
- Pthreads
- Unison I/O Library
- Unison STDIO Library
- STDIO Library Calls
- clearerr()
- dprintf()
- fclose()
- fdopen()
- feof()
- ferror()
- fileno()
- fflush()
- fgetc()
- fgetpos()
- fgets()
- fopen()
- fprintf()
- fputc()
- fputs()
- fread()
- freopen()
- fscanf()
- fseek()
- fseeko()
- fsetpos()
- ftell()
- ftello()
- fwrite()
- getc()
- getc_unlocked()
- getchar()
- getchar_unlocked()
- getdelim()
- getline()
- gets()
- get_stderr_ptr()
- get_stdin_ptr()
- get_stdout_ptr()
- noperprintf()
- perprintf()
- perror()
- posix_compat()
- printf()
- putc()
- putc_unlocked()
- putchar()
- putchar_unlocked()
- puts()
- remove()
- rewind()
- scanf()
- setbuf()
- setvbuf()
- snprintf()
- sprintf()
- sscanf()
- stderr_init()
- stderr_close()
- stdin_init()
- stdin_close()
- stdout_init()
- stdout_close()
- vdprintf()
- vscanf()
- vsscanf()
- vfscanf()
- vprintf()
- vsnprintf()
- vsprintf()
- vfprintf()
- ungetc()
- Do-nothing Stubs
- STDIO Library Calls
- Unison LIBC Library
- Unison I/O Servers
- Graphics, Camera, Video, Audio
- Network Protocols
- TCP and UDP Server - tcpd
- DHCP Client Service - dhcp client
- DHCP Server - dhcpd
- Telnet Server - telnetd
- Tiny FTP Server - tftpd
- Point to Point - pppd
- Network Translation - NAT with PAT
- Firewall
- Tiny HTTP Server - thttpd
- Tiny HTTP Server with TLS
- POP3 Server
- Simple Mail Transfer Protocol Services (SMTP)
- Bootp Protocol
- File Transfer Protocol Server (FTP)
- File Transfer Client Services
- RPC / XDR
- DNS Client
- HTTP/HTTPS Client
- REST Client
- AutoIP Service - autoip client
- mDNS server - mdnsd
- SNTP Client
- SNMP Agent - Snmpd server
- SSL/TLS library
- SSH server
- IP security
- Power Control
- Serial I/O
- System Services
- Universal Serial Bus (USB)
- Wireless
- Remedy Tools for Unison
7.32.1.Remedy Data Logging and Event Display Tools #
OVERVIEW
The Remedy Data Logging and Event Display Tools consist of two components:
– Remedy Data Logger: target side logging component.
– Remedy Event and Remote Control Viewer: host side display component.
The Remedy Event and Remote Control Viewer is a host IDE specific tool, therefore it were described in separate file: see directory installdir/manuals.
The Remedy Data Logger is an IDE independent target component. Its operation is described below.
NAME
Data Logger – dlog
SYNOPSIS
#include <dlog.h>
- pthread_create(&dlogTid, &dlogattr, (void *)dlog, (void *)&dlog_init);
THREAD dlog(struct dlog_settings *dlog_init);
- User events functions:
int dlog_thread_mask(pthread_t id, uint_32 mask);
int dlog_interrupt_mask(int vector, uint_32 mask);
void dlog_set_thread_name(pthread_t id, char *name);
void dlog_set_interrupt_name(int vector, char *name);
void dlog_data(uint_32 d1, uint_32 d2, uint_32 d3, uint_32 d4, uint_32 d5, uint_32 d6);
void dlog_str(char *str);
void dlog_raw(uchar *raw, int num);
- Triggers control functions
int dlog_SetTrigVal(uint_8 TrigNum, uint_32 lt_val, uint_32 *lt_ptr, uint_32 eq_val, uint_32 *eq_ptr, uint_32 gt_val, uint_32 *gt_ptr, uint_8 valMask);
int dlog_SetTrigUsr(int(*func)(void));
int dlog_SetSeqMasks(uint_8 SeqMask1, uint_8 SeqMask2, uint_8 SeqMask3, uint_8 SeqMask4, uint_8 TrigBufLoc);
- Dlog work control functions
int dlog_SetLogMode(uint_8 Mode);
int dlog_ForceSendLog(void);
DESCRIPTION
The dlog server provides system events logging. Dlog collects and analyses events from all threads, servers and interrupts.
User can choose, what types of events will be logged. It is possible to set the global mask of events for all streams or individually for every stream, server or interrupt.
Dlog server events masks and their functions:
Kernel log events mask:
-
- DLOG_MASK_MALLOC
-
- – malloc(), free()
-
- DLOG_MASK_POOL
-
- – pool_create(), pool_destroy(), pool_alloc(), pool_free()
-
- DLOG_MASK_PT
-
- – pt_create(), pt_destroy(), pt_getblock(), pt_freeblock()
-
- DLOG_MASK_MQ
-
- – mq_open(), mq_close(), mq_unlink(), mq_receive() / mq_timedreceive(), mq_send() / mq_timedsend()
-
- DLOG_MASK_MR
-
- – mr_init(), mr_receive(), mr_reply(), mr_send(), mr_sigpost(), mr_sigrecv()
-
- DLOG_MASK_BARRIER
-
- – pthread_barrier_init(), pthread_barrier_destroy(), pthread_barrier_wait()
-
- DLOG_MASK_CANCEL
-
- – pthread_cancel(), pthread_testcancel(), pthread_cleanup_push(), pthread_cleanup_pop(), pthread_setcancelstate(), pthread_setcanceltype()
-
- DLOG_MASK_COND
-
- – pthread_cond_init(), pthread_cond_destroy(), pthread_cond_broadcast(), pthread_cond_signal(), pthread_cond_wait()
-
- DLOG_MASK_PTHREAD_STATE
-
- – pthread_create(), pthread_exit(), pthread_join(), sched_yield()
-
- DLOG_MASK_MUTEX
-
- – pthread_mutex_init(), pthread_mutex_destroy(), pthread_mutex_lock(), pthread_mutex_trylock(), pthread_mutex_unlock()
-
- DLOG_MASK_SEM
-
- – sem_open(), sem_init(), sem_close(), sem_destroy(), sem_unlink(), sem_post(), sem_wait(), sem_timedwait(), sem_trywait()
-
- DLOG_MASK_SLEEP
-
- – nanosleep()
-
- DLOG_MASK_TIMER
-
- – timer_create(), timer_delete(), timer_gettime(), timer_settime()
-
- DLOG_MASK_CLOCK
-
- – clock_init(), clock_settime(), clock_getres(), clock_gettime()
-
- DLOG_MASK_KERNEL_ALL
-
- – all above kernel functions
User log events mask:
-
- DLOG_MASK_USER
-
- – dlog_data(), dlog_str(), dlog_raw()
Iolib log events mask:
-
- DLOG_MASK_SOCKET
-
- – open(), close(), socket(), bind(), connect(), listen(), accept(), select(), recv(), recvfrom(), send(), sendto(), shutdown(), getpeername(), getsockname(), getsockopt(), setsockopt()
-
- DLOG_MASK_FS
-
- – open(), close(), mkfs(), mount(), nfsmount(), umount(), create(), link(), unlink(), sync(), fsync(), fstat(), stat(), chmod(), lseek(), mkdir(), rmdir(), getdirentries()
-
- DLOG_MASK_RDWR
-
- – open(), close(), read(), write(), ioctl()
-
- DLOG_MASK_IOLIB_ALL
-
- – all above iolib functions
Others mask:
-
- DLOG_MASK_INTERRUPT
-
- – log interrupts events
-
- DLOG_MASK_ALL
-
- – global mask for all events
The dlog server logs events in compliance with specified threads, interrupts and global masks and sends these events to remote host and/or writes its to a file.
Dlog server initialization
The dlog server initiatization structure can be found in the file <dlog.h>:
/* * dlog initialization structure */ struct dlog_settings { int log_buff_size; // events buffer - events count uint_32 polling_interval; // events polling interval - ms int flush_edge; // minimum flush events count uint_32 event_mask; // logging events - global mask char threads_flow_log; // log or not threads flow char *log_file; // write log in file uint_32 file_len; // maximum log file length char *remote_ip; // send log to remote host u_short remote_port; };
At initialization dlog allocates memory for log_buff_size events. All threads and interrupts write their events in this shared buffer. The Dlog server scans the buffer with a polling_interval period. If number of events in the buffer is equal to or greater than flush_edge – dlog sends the log to the remote host or/and writes in file.
Dlog has a global events mask event_mask. This mask applies with all threads and interrupts masks. The kernel has some internal unmaskable events for tracking threads context switch trace. These events are necessary for the correct interpretation of behavior of the system. These events can be removed from log if threads_flow_log is set to zero.
If a log_file was specified, dlog will write events in this file. If the file_len is not equal to zero, dlog will write the log in separate files with sizes not more, than file_len bytes. Log files will be named as “user file name” + “file number”.
If remote_ip was specified, dlog will send events to this IP-address at port remote_port by UDP protocol.
User events functions
Dlog has different user functions for logging event management.
int dlog_thread_mask(pthread_t id, uint_32 mask);
Set event mask mask for thread id.
int dlog_interrupt_mask(int vector, uint_32 mask);
Set event mask mask for interrupt vector.
void dlog_set_thread_name(pthread_t id, char *name);
Set name *name for thread id. Maximum name length can be 32 bytes.
void dlog_set_interrupt_name(int vector, char *name);
Set name *name for interrupt vector. Maximum name length can be 32 bytes.
void dlog_data(uint_32 d1, uint_32 d2, uint_32 d3, uint_32 d4, uint_32 d5, uint_32 d6);
Generate user log dats event. User can logged up to sixt 32-bits unsigned values.
void dlog_str(char *str);
Generate user log string event. Maximum string length can be 24 bytes.
void dlog_raw(uchar *raw, int num);
Generate user log raw buffer event. Maximum buffer length can be 24 bytes.
Triggers control functions
Dlog has an additional operational mode – send log only if some conditions are met. This behavior is realized with help of a triggers mechanizm which is used for setting up the specific condition for logging. There are 3 “value” triggers and 1 “user” trigger. The system analyzes all enabled triggers and if a trigger or triggers sequence was latched, dlog sends or writes all logged events from the buffer.
int dlog_SetTrigVal(uint_8 TrigNum, uint_32 lt_val, uint_32 *lt_ptr, uint_32 eq_val, uint_32 *eq_ptr, uint_32 gt_val, uint_32 *gt_ptr, uint_8 valMask);
Setup “value trigger” number TrigNum. User can set:
– value lt_val and address *lt_ptr: trigger will be latched if value at address *lt_ptr will be less than lt_val;
– value eq_val and address *eq_ptr: trigger will be latched if value at address *eq_ptr will be equal than eq_val;
– value gt_val and address *gt_ptr: trigger will be latched if value at address *gt_ptr will be greate than lt_val.
With the help of valMask the user can choose activity masks and its logical operation:
– TRIG_LT_VAL: scan “less than” value;
– TRIG_EQ_VAL: scan “equal to” value;
– TRIG_GT_VAL: scan “greater than” value;
– VALS_AND: trigger will be latched if all selected items are true values. By default the item is latched if one of the values is true.
int dlog_SetTrigUsr(int(*func)(void));
Setup “user trigger” function *func. Trigger will be latched, if user function return 1. If the user condition is not true, the function must returns 0.
int dlog_SetSeqMasks(uint_8 SeqMask1, uint_8 SeqMask2, uint_8 SeqMask3, uint_8 SeqMask4, uint_8 TrigBufLoc);
Dlog has triggers sequence masks and buffer position control. Dlog checks triggers from SeqMask1, then from SeqMask2, then from SeqMask3 and from SeqMask4. Masks bits:
– TRIG_VAL3: wait “value trigger” #3;
– TRIG_VAL2: wait “value trigger” #2;
– TRIG_VAL1: wait “value trigger” #1;
– TRIG_USER: wait “user trigger”;
– TRIGS_AND: log will be send/write if all selected triggers are latched. By default this is true if one of the triggers is latched.
Parameter TrigBufLoc setup latched trigger location inside logged buffer:
– TRIG_BUFF_BEFORE: send all events, which were written to the buffer before the trigger;
– TRIG_BUFF_AFTER: send all events, which were writen to the buffer after the trigger;
– TRIG_BUFF_MIDDLE: send half the buffer events which were written to buffer before trigger, and half buffer events which were written to buffer after trigger.
Dlog work control functions
int dlog_SetLogMode(uint_8 Mode);
Set dlog work mode. Parameter Mode can be:
– LOG_OFF: not log events;
– LOG_NOSEND: log events, but not send/write its;
– LOG_AUTOLOG: log events and always send/write its;
– LOG_TRIG_SINGLE: log events and wait trigger. After trigger occurs – send log buffer and switch to LOG_NOSEND mode;
– LOG_TRIG_CONTINUE: log events and wait trigger. After trigger occurs – send log buffer and continue.
int dlog_ForceSendLog(void);
If dlog works in LOG_NOSEND mode, user can send/write current buffer with logged events.
RETURN VALUES
All dlog functions return 0 on success and -1 on all other conditions.
ERRORS
All errors are handled by the return values.
EXAMPLE
This partial example shows the creation and registration of the dlog server.
#include <dlog.h> /* * dlog variables and start routine */ struct dlog_settings dlog_init; void dlog_start(void) { pthread_t dlogTid; pthread_attr_t dlogattr; struct sched_param dlogPriority; // Fill parameters dlog_init.log_buff_size = 50; dlog_init.polling_interval = 30; dlog_init.flush_edge = 10; dlog_init.event_mask = DLOG_MASK_ALL; dlog_init.threads_flow_log = 1; dlog_init.log_file = "/dev/rd/tftpboot/logfile"; dlog_init.file_len = 2048; dlog_init.remote_ip = "192.168.16.2"; dlog_init.remote_port = 15000; pthread_attr_init(&dlogattr); pthread_attr_setstacksize(&dlogattr, 1400); dlogPriority.sched_priority = 6; pthread_attr_setschedparam(&dlogattr, &dlogPriority); pthread_create(&dlogTid, &dlogattr, (void *)dlog, (void *)&dlog_init); pthread_attr_destroy(&dlogattr); }
After creation, you must set logged interrupts and threads
. . . dlog_start(); sleep(1); // Main dlog_set_thread_name(pthread_self(), "MainThread"); dlog_thread_mask(pthread_self(), DLOG_MASK_ALL); // System timer dlog_set_interrupt_name(TIMER_INTERRUPT_ID, "SysTimer"); dlog_interrupt_mask(TIMER_INTERRUPT_ID, DLOG_MASK_ALL); // Ethernet dlog_set_interrupt_name(ETH_INTERRUPT_ID, "EthernetInt"); dlog_set_thread_name(tcp_tid, "tcpd"); dlog_interrupt_mask(ETH_INTERRUPT_ID, DLOG_MASK_ALL); dlog_thread_mask(tcp_tid, DLOG_MASK_ALL); // fsys dlog_set_thread_name(fsys_tid, "fsys"); dlog_thread_mask(fsys_tid, DLOG_MASK_ALL); // tftpd dlog_set_thread_name(tftp_tid, "tftpd"); . . .
If need them, you can setup triggers
. . . // set trigger value (trig at =5 or >15) dlog_SetTrigVal(1, // trigger value #1 0, NULL, // lt_val 5, &var, // eq_val 15, &var, // gt_val TRIG_EQ_VAL | TRIG_GT_VAL); // trigger at eq_val or gt_val // set user trigger dlog_SetTrigUsr(UserTrig); // wait trigger value #1 or user trigger dlog_SetSeqMasks(TRIG_VAL1 | TRIG_USER, 0, 0, 0, TRIG_BUFF_MIDDLE); // do not stop logging after trigger dlog_SetLogMode(LOG_TRIG_SINGLE); . . .
NOTES
There is a demo available for the Unison and DSPnano dlog server which is found in installdir/demos.