write()-call return values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I want to test the fasted transmit speed of my socketcan.

Attached my simple test.


I want to write message by message to socketcan without a break.

I expect an error return value, if I cannot write, because the queue is
full.

I count only correct written values.


On my system only 9772 messages from 10000 are transmitted. On a
different customer system only around 2700 messages are transmitted.

Can you please check, if I have a mistake in my test program?

Do you have an other idea?


I test on a classical CAN bus with a bitrate of 250kbit/s.

The analyzer on a second device and also a test with a local candump
also connected to can0, show the same values.

Which information are required?

Which part of the socketcan software is related to this problem?


$ uname -a
Linux **** 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018
x86_64 x86_64 x86_64 GNU/Linux

after some test:

$ ip -details -statistics link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc fq_codel state UNKNOWN
mode DEFAULT group default qlen 10000
   link/can  promiscuity 0  
   can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0  
         bitrate 250000 sample-point 0.875  
         tq 25 prop-seg 69 phase-seg1 70 phase-seg2 20 sjw 1
         pcan_usb_fd: tseg1 1..256 tseg2 1..128 sjw 1..128 brp 1..1024
brp-inc 1
         pcan_usb_fd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..1024
dbrp-inc 1
         clock 80000000
         re-started bus-errors arbit-lost error-warn error-pass bus-off
         0          0          0          0          0          0
        numtxqueues 1 numrxqueues 1 gso_max_size 65536
gso_max_segs 65535  
   RX: bytes  packets  errors  dropped overrun mcast    
   895568     393815   0       0       0       0        
   TX: bytes  packets  errors  dropped carrier collsns  
   32413275   8959110  0       0       0       0      



5: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc fq_codel state UNKNOWN
mode DEFAULT group default qlen 10000
   link/can  promiscuity 0  
   can state ERROR-ACTIVE restart-ms 100  
         bitrate 250000 sample-point 0.875  
         tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
         kvaser_usb: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
         clock 8000000
         re-started bus-errors arbit-lost error-warn error-pass bus-off
         1          0          0          0          0          0
        numtxqueues 1 numrxqueues 1 gso_max_size 65536
gso_max_segs 65535  
   RX: bytes  packets  errors  dropped overrun mcast    
   8          1        0       0       0       0        
   TX: bytes  packets  errors  dropped carrier collsns  
   117096     39032    0       0       0       0    


My system is a desktop with a peak usb interface , second test with
kvaser usb. The value of qlen seams

to be irrelevant for this test. I also don't get a full error on
qlen=10. Never.

Our customer use an embedded Linux with a PIC express card, completely
other than my system.

I'm sorry, I don't have more detail information.

My question is related to my testprogram attached to this mail.


Thank you

Steffen

/* header of standard C - libraries
---------------------------------------------------------------------------*/
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

/* OS headers
---------------------------------------------------------------------------*/
#include <net/if.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <linux/can/error.h>

#define CAN_INTERFACE "can0"
const char * interface_cstr = CAN_INTERFACE;

static int    mBSDSocket;	/*!< handle of BSD socket */
struct ifreq ifr;
struct sockaddr_can addr;
struct can_frame frame;

int main(int par)
{
int i; /*! loop counter */
ssize_t nbytes;

	printf("frame size: %ld\n", sizeof(frame));

    /* create RAW socket for CAN */
    mBSDSocket = socket(PF_CAN, SOCK_RAW, CAN_RAW);
    if (mBSDSocket < 0) {
		exit(-1);
	}

   /* link socket to specified CAN interface */
    addr.can_family = AF_CAN;
    strcpy(ifr.ifr_name, interface_cstr);
    printf("using SocketCAN device %s\n", ifr.ifr_name);

    if (ioctl(mBSDSocket, SIOCGIFINDEX, &ifr) < 0) {
		exit(-2);
    }
    addr.can_ifindex = ifr.ifr_ifindex;

    /* bind to socket, so that we can receive messages from it */
    if (bind(mBSDSocket, (const struct sockaddr *)&addr, sizeof(addr)) < 0) {
		exit(-3);
    }

	printf("Init ready\n");

	i = 0;
	do {

		frame.can_id  = 0x001; //classic 11bit ID data frame
		frame.can_dlc = 3;
		frame.data[0] = i & 0xFF;
		frame.data[1] = (i >> 8) & 0xFF;
		frame.data[2] = 2;
		frame.data[3] = 3;
		frame.data[4] = 4;
		frame.data[5] = 5;
		frame.data[6] = 6;
		frame.data[7] = 7;

		/* send the can frame */
		nbytes = write(mBSDSocket, &frame, sizeof(frame));
		if (nbytes < 0) {
			printf("Error %ld\n", nbytes);
		}

		if (nbytes != sizeof(frame)) 
		{
			printf("Wrong Frame size: %ld\n", nbytes);
		} 

		if (nbytes == sizeof(frame)) 
		{
			i++;
		}

		//usleep(500);

	} while(i < 10000);

}

[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux