<div dir="ltr">Hi All, <div><br></div><div><br></div><div>I have implemented a dbus application using dbus-1 API's on linux platform and testing profiling on ubuntu machine . Get issue as mentioned below </div><div><br></div><div>Following are the challenges facing </div><div><br></div><div>1. I have implemented dbus communication using signaling , dbus initialization , dbus publish and dbus subscribe</div><div>2. When I started testing on the linux ubuntu machine for profiling of dbus message Transmit from one process and receiver another process using dbus signaling, It's working fine for the first 15 minutes , latency time is on average 500 microSeconds. After 30 minutes, 20 -30 messages are getting latency of 80 milliseconds . Each message transmitted at 1 millisecond delay</div><div>Latency time between transmitting from one process and receiving at another process is not constant for the same payload message. <br></div><div>3. Is any benchmark for message transmit and receiver timeline (latency time) <br></div><div><br></div><div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254);font-family:Consolas,"Courier New",monospace;font-size:12px;line-height:16px;white-space:pre"><div><span style="color:rgb(0,114,0)">/**</span></div><div><span style="color:rgb(0,114,0)"> * Initialize dbus.pass the unique application name as argument. this name will</span></div><div><span style="color:rgb(0,114,0)"> * be used to identify the dbus object and path name in the later calls.</span></div><div><span style="color:rgb(0,114,0)"> * @param appname unique application identifier name.</span></div><div><span style="color:rgb(0,114,0)"> * @return 0 on success error code otherwise.</span></div><div><span style="color:rgb(0,114,0)"> */</span></div><div><span style="color:rgb(0,0,255)">int</span> dbus_client_init (<span style="color:rgb(0,0,255)">char</span> *appname)</div><div>{</div><div> <span style="color:rgb(0,0,255)">struct</span> timespec wait = {<span style="color:rgb(0,114,0)">0</span>};</div><br><div> flogd(<span style="color:rgb(163,21,21)">"dbustest.log"</span>,<span style="color:rgb(163,21,21)">"%s:%d Entry"</span>,__func__,__LINE__);</div><div> DBusError err;</div><div> <span style="color:rgb(0,0,255)">int</span> rc = <span style="color:rgb(0,114,0)">0</span>;</div><div> printf(<span style="color:rgb(163,21,21)">"appname=%s\n"</span>,appname);</div><br><div> <span style="color:rgb(0,114,0)">// lock mutex</span></div><div> wait.tv_sec = <span style="color:rgb(0,114,0)">0</span>;</div><div> wait.tv_nsec = MS_TO_NS(MILLI_SEC); <span style="color:rgb(0,114,0)">// 500 msec</span></div><br><div> <span style="color:rgb(0,114,0)">//pthread_mutex_lock (&init_dbus_mutex);</span></div><div> <span style="color:rgb(0,0,255)">if</span>(pthread_mutex_timedlock(&init_dbus_mutex, &wait) == <span style="color:rgb(0,114,0)">0</span>)</div><div> {</div><div> flogd(<span style="color:rgb(163,21,21)">"dbustest.log"</span>,<span style="color:rgb(163,21,21)">"%s:%d Entry"</span>,__func__,__LINE__);</div><div> <span style="color:rgb(0,0,255)">if</span> (init_dbus_flag == <span style="color:rgb(0,0,255)">false</span>)</div><div> {</div><div> <span style="color:rgb(0,114,0)">// initialize the errors</span></div><div> dbus_error_init(&err);</div><br><div> <span style="color:rgb(0,114,0)">// connect to the system bus and check for errors</span></div><div> txconn = dbus_bus_get(DBUS_BUS_SESSION, &err);</div><div> <span style="color:rgb(0,0,255)">if</span> (dbus_error_is_set(&err))</div><div> {</div><div> flogd(<span style="color:rgb(163,21,21)">"dbustest.log"</span>,<span style="color:rgb(163,21,21)">"%s:%d txbus: Connection Error (%s)"</span>,__func__,__LINE__, err.message);</div><div> dbus_error_free(&err);</div><div> pthread_mutex_unlock (&init_dbus_mutex);</div><div> <span style="color:rgb(0,0,255)">return</span> -<span style="color:rgb(0,114,0)">1</span>;</div><div> }</div><div> <span style="color:rgb(0,0,255)">if</span> (NULL == txconn)</div><div> {</div><div> dbus_error_free(&err);</div><div> pthread_mutex_unlock (&init_dbus_mutex);</div><div> <span style="color:rgb(0,0,255)">return</span> -<span style="color:rgb(0,114,0)">1</span>;</div><div> }</div><br><div> <span style="color:rgb(0,114,0)">// request our name on the bus</span></div><div> sprintf(txbusname + strlen(txbusname), <span style="color:rgb(163,21,21)">"%s"</span>, appname);</div><div> rc = dbus_bus_request_name(txconn, txbusname, DBUS_NAME_FLAG_REPLACE_EXISTING , &err);</div><div> <span style="color:rgb(0,0,255)">if</span> (dbus_error_is_set(&err) || rc == -<span style="color:rgb(0,114,0)">1</span>)</div><div> {</div><div> flogd(<span style="color:rgb(163,21,21)">"dbustest.log"</span>, <span style="color:rgb(163,21,21)">"%s:%d txbus: Name Error (%s)"</span>,__func__,__LINE__, err.message);</div><div> dbus_error_free(&err);</div><div> pthread_mutex_unlock (&init_dbus_mutex);</div><div> <span style="color:rgb(0,0,255)">return</span> -<span style="color:rgb(0,114,0)">1</span>;</div><div> }</div><br><div> <span style="color:rgb(0,114,0)">// connect to the system bus and check for errors</span></div><div> rxconn = dbus_bus_get(DBUS_BUS_SESSION, &err);</div><div> <span style="color:rgb(0,0,255)">if</span> (dbus_error_is_set(&err))</div><div> {</div><div> flogd(<span style="color:rgb(163,21,21)">"dbustest.log"</span>,<span style="color:rgb(163,21,21)">"%s:%d rxbus: Connection Error (%s)"</span>,__func__,__LINE__, err.message);</div><div> dbus_error_free(&err);</div><div> pthread_mutex_unlock (&init_dbus_mutex);</div><div> <span style="color:rgb(0,0,255)">return</span> -<span style="color:rgb(0,114,0)">1</span>;</div><div> }</div><div> <span style="color:rgb(0,0,255)">if</span> (NULL == rxconn)</div><div> {</div><div> dbus_error_free(&err);</div><div> pthread_mutex_unlock (&init_dbus_mutex);</div><div> <span style="color:rgb(0,0,255)">return</span> -<span style="color:rgb(0,114,0)">1</span>;</div><div> }</div><br><div> <span style="color:rgb(0,114,0)">// request our name on the bus</span></div><div><span style="color:rgb(0,114,0)">// sprintf(rxbusname + strlen(rxbusname), "%d", getpid());</span></div><div> sprintf(rxbusname + strlen(rxbusname), <span style="color:rgb(163,21,21)">"%s"</span>, appname);</div><div> printf(<span style="color:rgb(163,21,21)">"%s\n"</span>,rxbusname);</div><div> rc = dbus_bus_request_name(rxconn, rxbusname, DBUS_NAME_FLAG_REPLACE_EXISTING , &err);</div><div> <span style="color:rgb(0,0,255)">if</span> (dbus_error_is_set(&err) || rc == -<span style="color:rgb(0,114,0)">1</span>)</div><div> {</div><div> flogd(<span style="color:rgb(163,21,21)">"dbustest.log"</span>, <span style="color:rgb(163,21,21)">"%s:%d rxbus: Name Error (%s)"</span>,__func__,__LINE__, err.message);</div><div> dbus_error_free(&err);</div><div> pthread_mutex_unlock (&init_dbus_mutex);</div><div> <span style="color:rgb(0,0,255)">return</span> -<span style="color:rgb(0,114,0)">1</span>;</div><div> }</div><br><div> dbus_error_free(&err);</div><div> init_dbus_flag = <span style="color:rgb(0,0,255)">true</span>;</div><div> }</div><div> <span style="color:rgb(0,0,255)">else</span></div><div> {</div><div> flogv(<span style="color:rgb(163,21,21)">"dbustest.log"</span>,<span style="color:rgb(163,21,21)">"%s:%d Dbus was already initialized"</span>,__func__,__LINE__);</div><div> }</div><br><div> pthread_mutex_unlock (&init_dbus_mutex);</div><div> }</div><div> <span style="color:rgb(0,0,255)">else</span></div><div> {</div><div> flogd(<span style="color:rgb(163,21,21)">"dbustest.log"</span>,<span style="color:rgb(163,21,21)">"%s:%d Exit (no errors)"</span>,__func__,__LINE__);</div><div> <span style="color:rgb(0,0,255)">return</span> -<span style="color:rgb(0,114,0)">1</span>;</div><div> }</div><div> <span style="color:rgb(0,0,255)">return</span> <span style="color:rgb(0,114,0)">0</span>;</div><div>}</div><div><br></div><div>
<div style="line-height:16px"><div><span style="color:rgb(0,0,255)">int</span> dbus_client_publish (<span style="color:rgb(0,0,255)">char</span> *method, <span style="color:rgb(0,0,255)">void</span> *payload, <span style="color:rgb(0,0,255)">int</span> payloadlen)</div><div>{</div><div> DBusMessage *msg;</div><div> DBusMessageIter args;</div><div> DBusMessageIter subiter;</div><div> DBusError err;</div><br><div> <span style="color:rgb(0,0,255)">int</span> returnValue = -<span style="color:rgb(0,114,0)">1</span>;</div><div> <span style="color:rgb(0,0,255)">int</span> SignalRetryCount = <span style="color:rgb(0,114,0)">0</span>;</div><div> <span style="color:rgb(0,0,255)">int</span> SendRetryCount = <span style="color:rgb(0,114,0)">0</span>;</div><div> <span style="color:rgb(0,0,255)">int</span> maxRetries = <span style="color:rgb(0,114,0)">3</span>;</div><div> <span style="color:rgb(0,0,255)">int</span> successConnect = <span style="color:rgb(0,114,0)">0</span>;</div><div> <span style="color:rgb(0,0,255)">int</span> successSend = <span style="color:rgb(0,114,0)">0</span>;</div><br><div> <span style="color:rgb(0,0,255)">char</span> *pload = (<span style="color:rgb(0,0,255)">char</span>*) payload;</div><br><div> <span style="color:rgb(0,0,255)">if</span>(pload != NULL)</div><div> {</div><div> <span style="color:rgb(0,114,0)">// initialize the errors</span></div><div> dbus_error_init (&err);</div><br><div> <span style="color:rgb(0,0,255)">while</span> (SignalRetryCount < maxRetries && !successConnect)</div><div> {</div><br><div> <span style="color:rgb(0,114,0)">// create a new method call and check for errors</span></div><div> msg = dbus_message_new_signal (DBUS_OBJECT_NAME, <span style="color:rgb(0,114,0)">// object name of the signal</span></div><div> DBUS_INTERFACE_NAME, <span style="color:rgb(0,114,0)">// interface name of the signal</span></div><div> method); <span style="color:rgb(0,114,0)">// name of the signal</span></div><br><div> <span style="color:rgb(0,0,255)">if</span>(NULL == msg)</div><div> {</div><div> dbus_error_free (&err);</div><br><div> SignalRetryCount++;</div><div> }</div><div> <span style="color:rgb(0,0,255)">else</span></div><div> {</div><div> <span style="color:rgb(0,114,0)">// append arguments</span></div><div> dbus_message_iter_init_append (msg, &args);</div><br><div> <span style="color:rgb(0,114,0)">// For appending args, doc says to use the following 3 for container types.</span></div><div> <span style="color:rgb(0,114,0)">// We can view the cmd buffer as a char buffer and send</span></div><div> dbus_message_iter_open_container (&args, DBUS_TYPE_ARRAY, <span style="color:rgb(163,21,21)">"y"</span>, &subiter);</div><div> dbus_message_iter_append_fixed_array (&subiter, DBUS_TYPE_BYTE, &pload, payloadlen);</div><br><div> dbus_message_iter_close_container (&args, &subiter);</div><br><div> <span style="color:rgb(0,114,0)">// We probably don't need a reply</span></div><div> <span style="color:rgb(0,114,0)">// flogv("dbustest.log","%s:%d dbus_connection_send called",__func__,__LINE__);</span></div><br><div> <span style="color:rgb(0,0,255)">while</span> (SendRetryCount < maxRetries && !successSend)</div><div> {</div><div> <span style="color:rgb(0,0,255)">if</span>(!dbus_connection_send (txconn, msg, NULL))</div><div> {</div><div> <span style="color:rgb(0,114,0)">// flogd("dbustest.log","%s:%d Out Of Memory!",__func__,__LINE__);</span></div><div> SendRetryCount++;</div><div> }</div><div> <span style="color:rgb(0,0,255)">else</span></div><div> {</div><div> successConnect = <span style="color:rgb(0,114,0)">1</span>;</div><div> successSend = <span style="color:rgb(0,114,0)">1</span>;</div><div> returnValue = <span style="color:rgb(0,114,0)">0</span>;</div><div> <span style="color:rgb(0,0,255)">break</span>;</div><div> }</div><div> }</div><div> }</div><div> }</div><br><div> dbus_connection_flush (txconn);</div><br><div> <span style="color:rgb(0,114,0)">// free message</span></div><div> dbus_message_unref (msg);</div><div> dbus_error_free (&err);</div><br><div> <span style="color:rgb(0,114,0)">//flogd("dbustest.log","%s:%d Exit (no errors)",__func__,__LINE__);</span></div><div> }</div><br><div> <span style="color:rgb(0,114,0)">// print ( dbus_client_publish, returnValue)</span></div><br><div> <span style="color:rgb(0,0,255)">return</span> returnValue;</div><div>}</div></div>
<div style="line-height:16px"><div><span style="color:rgb(0,114,0)">/* This API subscribes for a particular busname/interface/method. The callback would</span></div><div><span style="color:rgb(0,114,0)"> * be called once the subscribed information is available.</span></div><div><span style="color:rgb(0,114,0)"> *Note: subscribe = listen => server bus name (e.g., mqtt.server.cmdhndlr).</span></div><div><span style="color:rgb(0,114,0)"> *</span></div><div><span style="color:rgb(0,114,0)"> * method: method name you want to listen to.</span></div><div><span style="color:rgb(0,114,0)"> * cb: callback to be called once the subscribed information is available.</span></div><div><span style="color:rgb(0,114,0)"> * return: 0 on success, -1 on failure.</span></div><div><span style="color:rgb(0,114,0)"> */</span></div><div><span style="color:rgb(0,0,255)">int</span> dbus_client_subscribe (<span style="color:rgb(0,0,255)">int</span> num_pairs, ...)</div><div>{</div><div> flogd(<span style="color:rgb(163,21,21)">"dbustest.log"</span>,<span style="color:rgb(163,21,21)">"%s:%d Entry"</span>,__func__,__LINE__);</div><div> <span style="color:rgb(0,0,255)">int</span> i;</div><div> va_list vargs;</div><div> rx_thread_args_t *args;</div><br><div> <span style="color:rgb(0,0,255)">if</span> (num_pairs > <span style="color:rgb(0,114,0)">32</span>)</div><div> <span style="color:rgb(0,0,255)">return</span> -<span style="color:rgb(0,114,0)">1</span>;</div><br><div> args = (rx_thread_args_t *) malloc (<span style="color:rgb(0,0,255)">sizeof</span>(rx_thread_args_t));</div><div> <span style="color:rgb(0,0,255)">if</span> (args == NULL)</div><div> <span style="color:rgb(0,0,255)">return</span> -<span style="color:rgb(0,114,0)">1</span>;</div><br><div> args->num_pairs = num_pairs;</div><div> va_start(vargs, num_pairs);</div><div> <span style="color:rgb(0,0,255)">for</span> (i = <span style="color:rgb(0,114,0)">0</span>; i < num_pairs; i++)</div><div> {</div><div> <span style="color:rgb(0,0,255)">char</span> *m = va_arg(vargs, <span style="color:rgb(0,0,255)">char</span> *);</div><div> sprintf (args->mthod_cb[i].method, <span style="color:rgb(163,21,21)">"%s"</span>, m);</div><div> args->mthod_cb[i].cb = va_arg(vargs, <span style="color:rgb(0,0,255)">void</span> *);</div><div> }</div><div> va_end(vargs);</div><br><div> <span style="color:rgb(0,0,255)">if</span> (pthread_create (&dbus_client_rx_thread, NULL, dbus_client_receive_thread, (<span style="color:rgb(0,0,255)">void</span> *)args) != <span style="color:rgb(0,114,0)">0</span>)</div><div> {</div><div> floge(<span style="color:rgb(163,21,21)">"dbustest.log"</span>,<span style="color:rgb(163,21,21)">"%s:%d Client Error: Rx Thread creation failed; errno = %d (%s)"</span>,__func__,__LINE__, errno, strerror(errno));</div><div> <span style="color:rgb(0,0,255)">return</span> -<span style="color:rgb(0,114,0)">1</span>;</div><div> }</div><br><div> <span style="color:rgb(0,114,0)">/* TODO: Detach dbus_client_receive_thread. (or exit self in the created thread)</span></div><div><span style="color:rgb(0,114,0)"> * Cannot be joined here as it will block the client process.</span></div><div><span style="color:rgb(0,114,0)"> */</span></div><div> flogd(<span style="color:rgb(163,21,21)">"dbustest.log"</span>,<span style="color:rgb(163,21,21)">"%s:%d exit"</span>,__func__,__LINE__);</div><div> <span style="color:rgb(0,0,255)">return</span> <span style="color:rgb(0,114,0)">0</span>;</div><div>}</div></div>
<br></div><div>Please correct me, if anything is missing in my implementation. </div><div><br></div><div><br></div><div>Regards,</div><div>Deepak Jewargi </div><div>
</div></div></div><div><br></div><div><br></div></div>