Linux usb 6. HC/UDC 测试

2023-05-16

文章目录

  • 1. 背景介绍
  • 2. Device (gadget zero)
    • 2.1 `gadget zero` 创建
    • 2.2 SourceSink Function
    • 2.3 Loopback Function
  • 3. Host (usbtest.ko)
    • 3.1 testcase
    • 3.2 ioctl
  • 4. App (testusb)
  • 参考资料

1. 背景介绍

在测试 USB 时,普通的做法是找一些 U 盘、鼠标、键盘 等外设来做一些测试,但是这些测试还是偏上层偏功能的。相比较 HC (USB Host Controller) 和 UDC (USB Device Controller) 按照USB协议提供的完整功能来说,这种测试验证时不充分的。

在 Linux Kernel 中对 HC/UDC 有一套专有的测试方案,在底层对 control/bulk/int/iso 几种 endpoint 进行针对性的功能和压力测试。

在这里插入图片描述

上图的测试方案由几部分组成:

  • 1、Device 侧的 gadget zero 测试设备,提供了测试通道。
  • 2、Host 侧的 usbtest.ko 测试驱动,封装了 30 个 endpoint 层级的测试用例。
  • 3、Host 侧的 testusb 用户程序,用来调用 usbtest.ko 提供的测试用例。

2. Device (gadget zero)

提供测试需要的Device设备有很多种方式,例如可用使用专门的测试 Device 里面烧录专有的测试 Firmware。节约成本的方式还是使用 Linux gadget 功能来动态模拟 USB Device 设备。针对 USB 测试,Linux 专门提供了 gadget zero 设备。

2.1 gadget zero 创建

gadget zero 的核心是创建一个 Composite Device,其包含了两个 Configuration,其中一个 Configuration 0 包含 SourceSink Function/Interface,另一个 Configuration 1 包含 Loopback Function/Interface。某一时刻只能选择使用一个 Configuration,通常情况下使用 Configuration 0SourceSink的功能。

gadget zero 由两种方式创建:

  • 1、通过 zero_driver 创建,只要把对应驱动文件 drivers\usb\gadget\legacy\zero.c 编译进内核即可。
  • 2、通过 functionfs 动态创建,这种方式更灵活,实例命令如下:
mount -t configfs none /sys/kernel/config
cd /sys/kernel/config/usb_gadget

mkdir g2
cd g2

echo "0x04e8" > idVendor
echo "0x2d01" > idProduct

mkdir configs/c.1
mkdir configs/c.2
mkdir functions/Loopback.0
mkdir functions/SourceSink.0

mkdir strings/0x409
mkdir configs/c.1/strings/0x409
mkdir configs/c.2/strings/0x409

echo "0x0525" > idVendor
echo "0xa4a0" > idProduct

echo "0123456789" > strings/0x409/serialnumber
echo "Samsung Inc." > strings/0x409/manufacturer
echo "Bar Gadget" > strings/0x409/product

echo "Conf 1" > configs/c.1/strings/0x409/configuration
echo "Conf 2" > configs/c.2/strings/0x409/configuration
echo 120 > configs/c.1/MaxPower

// SourceSink:驱动 set configuration 会选取 第一个 configuration
ln -s functions/Loopback.0 configs/c.2
ln -s functions/SourceSink.0 configs/c.1

echo 4100000.udc-controller > UDC

整个过程就是创建了一个 Vendor ID = 0x0525Product ID = 0xa4a0Composite Device,在 Host 侧可以查看这个设备:

$ lsusb-s 1:3
Bus 001 Device 003: ID 0525:a4a0 Netchip Technology, Inc. Linux-USB "Gadget Zero"

$ lsusb -v -s 1:3

Bus 001 Device 003: ID 0525:a4a0 Netchip Technology, Inc. Linux-USB "Gadget Zero"
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x0525 Netchip Technology, Inc.
  idProduct          0xa4a0 Linux-USB "Gadget Zero"
  bcdDevice            5.10
  iManufacturer           1 
  iProduct                2 
  iSerial                 3 
  bNumConfigurations      2
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0045
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          4 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              120mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       1
      bNumEndpoints           4
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               4
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0020
    bNumInterfaces          1
    bConfigurationValue     2
    iConfiguration          5 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower                2mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              6 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0

2.2 SourceSink Function

SourceSink Function 的主要功能是提供了一组 USB 测试 endpoint,其中:

  • Sink。sinks bulk packets OUT to the peripheral。意思是把数据从 Host 引流到 Device,即 OUT 方向。
  • Source。sources them IN to the host。意思是把从 Device 发送数据到 Device,即 IN 方向。

具体提供了 4 组 测试 endpoint:

EndpointTypeDirectionDescript
in_epbulkINSource 发送数据到 Host,注意这数据是 Device 主动生成的
out_epbulkOUTSink 接收 Host 的数据
iso_in_episoINSource 发送数据到 Host
iso_out_episoOUTSink 接收 Host 的数据

主要流程如下:

drivers\usb\gadget\function\f_sourcesink.c:

sourcesink_bind():

static int
sourcesink_bind(struct usb_configuration *c, struct usb_function *f)
{

    /* (1) 从 gadget 中分配 2 个 bulk endpoint */
	/* allocate bulk endpoints */
	ss->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc);

	ss->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_sink_desc);

    /* (2) 如果支持ISO,再从 gadget 中分配 2 个 iso endpoint */
	/* allocate iso endpoints */
	ss->iso_in_ep = usb_ep_autoconfig(cdev->gadget, &fs_iso_source_desc);
	if (!ss->iso_in_ep)
		goto no_iso;

	ss->iso_out_ep = usb_ep_autoconfig(cdev->gadget, &fs_iso_sink_desc);
	if (!ss->iso_out_ep) {

}

sourcesink_set_alt() → enable_source_sink() → usb_ep_enable()/source_sink_start_ep():
// 启动上述 endpoint

→ source_sink_complete():
// urb 的 complete() 函数,urb 发送/接收完成后,重新挂载 urb

还支持一些参数调整:

# ls functions/SourceSink.0/
bulk_buflen     iso_qlen        isoc_maxburst   isoc_mult
bulk_qlen       isoc_interval   isoc_maxpacket  pattern

2.3 Loopback Function

Loopback Function 提供的功能更为简单,它分配了两个 bulk endpoint,所做的就是把 out_ep 接收到的数据 转发到 in_ep

主要流程如下:

drivers\usb\gadget\function\f_loopback.c:

loopback_bind():

static int loopback_bind(struct usb_configuration *c, struct usb_function *f)
{
    /* (1) 从 gadget 中分配 2 个 bulk endpoint */
	/* allocate endpoints */
	loop->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_loop_source_desc);

	loop->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_loop_sink_desc);
}

loopback_set_alt() → enable_loopback() → alloc_requests():

static int alloc_requests(struct usb_composite_dev *cdev,
			  struct f_loopback *loop)
{

	for (i = 0; i < loop->qlen && result == 0; i++) {
		result = -ENOMEM;

		in_req = usb_ep_alloc_request(loop->in_ep, GFP_ATOMIC);
		if (!in_req)
			goto fail;

		out_req = lb_alloc_ep_req(loop->out_ep, loop->buflen);
		if (!out_req)
			goto fail_in;

		in_req->complete = loopback_complete;
		out_req->complete = loopback_complete;

		in_req->buf = out_req->buf;
		/* length will be set in complete routine */
		in_req->context = out_req;
		out_req->context = in_req;

        /* (2) 先启动 OUT endpoint */
		result = usb_ep_queue(loop->out_ep, out_req, GFP_ATOMIC);
		if (result) {
			ERROR(cdev, "%s queue req --> %d\n",
					loop->out_ep->name, result);
			goto fail_out;
		}
	}

}

static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
{
	struct f_loopback	*loop = ep->driver_data;
	struct usb_composite_dev *cdev = loop->function.config->cdev;
	int			status = req->status;

	switch (status) {
	case 0:				/* normal completion? */
		if (ep == loop->out_ep) {
			/*
			 * We received some data from the host so let's
			 * queue it so host can read the from our in ep
			 */
			struct usb_request *in_req = req->context;

			in_req->zero = (req->actual < req->length);
			in_req->length = req->actual;
			ep = loop->in_ep;
			req = in_req;
		} else {
			/*
			 * We have just looped back a bunch of data
			 * to host. Now let's wait for some more data.
			 */
			req = req->context;
			ep = loop->out_ep;
		}

        /* (3) 环回的关键:
                OUT endpoint 接收到的数据 转发到 IN endpoint
                IN endpoint 数据发送完成后 req 重新挂载到 OUT endpoint
         */
		/* queue the buffer back to host or for next bunch of data */
		status = usb_ep_queue(ep, req, GFP_ATOMIC);

}

也支持一些参数调整:

# ls functions/Loopback.0/
bulk_buflen  qlen

3. Host (usbtest.ko)

在 Host 侧的 usbtest.ko 它就是一个标准的 usb interface driver。它根据 Vendor ID = 0x0525Product ID = 0xa4a0 适配上一节 Composite Device 中的 SourceSink Interface 或者 Loopback Interface

static const struct usb_device_id id_table[] = {

	/* "Gadget Zero" firmware runs under Linux */
	{ USB_DEVICE(0x0525, 0xa4a0),
		.driver_info = (unsigned long) &gz_info,
	},

}
MODULE_DEVICE_TABLE(usb, id_table);

static struct usb_driver usbtest_driver = {
	.name =		"usbtest",
	.id_table =	id_table,
	.probe =	usbtest_probe,
	.unlocked_ioctl = usbtest_ioctl,
	.disconnect =	usbtest_disconnect,
	.suspend =	usbtest_suspend,
	.resume =	usbtest_resume,
};

3.1 testcase

其在 SourceSink Interface 提供的 4 个测试 endpoint、或者 Loopback Interface 提供的 2 个测试 endpoint + Composite Device 本身的 ep0 control endpoint 基础之上,提供了30个 testcase:

drivers\usb\misc\usbtest.c: 

usbtest_do_ioctl()
indextypeiterationsvarysglenunalignedtestcasedescript
0nop----“TEST 0: NOP\n”-
1bulkY---“TEST 1: write %d bytes %u times\n”,
param->length, param->iterations
/* Simple non-queued bulk I/O tests */
2bulkY---“TEST 2: read %d bytes %u times\n”,
param->length, param->iterations
-
3bulkYY--“TEST 3: write/%d 0…%d bytes %u times\n”,
param->vary, param->length, param->iterations
-
4bulkYY--“TEST 4: read/%d 0…%d bytes %u times\n”,
param->vary, param->length, param->iterations
-
5bulkY-Y-“TEST 5: write %d sglists %d entries of %d bytes\n”,
param->iterations,param->sglen, param->length
/* Queued bulk I/O tests */
6bulkY-Y-“TEST 6: read %d sglists %d entries of %d bytes\n”,
param->iterations,param->sglen, param->length
-
7bulkYYY-“TEST 7: write/%d %d sglists %d entries 0…%d bytes\n”,
param->vary, param->iterations,param->sglen, param->length
-
8bulkYYY-“TEST 8: read/%d %d sglists %d entries 0…%d bytes\n”,
param->vary, param->iterations,param->sglen, param->length
-
9controlY---“TEST 9: ch9 (subset) control tests, %d times\n”,
param->iterations
/* non-queued sanity tests for control (chapter 9 subset) */
10controlY-Y-“TEST 10: queue %d control calls, %d times\n”,
param->sglen, param->iterations)
/* queued control messaging */
11bulkY---“TEST 11: unlink %d reads of %d\n”,
param->iterations, param->length
/* simple non-queued unlinks (ring with one urb) */
12bulkY---“TEST 12: unlink %d writes of %d\n”,
param->iterations, param->length
-
13controlY---"TEST 13: set/clear %d halts\n"
param->iterations
/* ep halt tests */
14controlYY--“TEST 14: %d ep0out, %d…%d vary %d\n”,
param->iterations,realworld ? 1 : 0, param->length,param->vary
/* control write tests */
15isoY-Y-“TEST 15: write %d iso, %d entries of %d bytes\n”,
param->iterations, param->sglen, param->length
/* iso write tests */
16isoY-Y-“TEST 16: read %d iso, %d entries of %d bytes\n”,
param->iterations, param->sglen, param->length
/* iso read tests */
17bulkY--Y"TEST 17: write odd addr %d bytes %u times core map\n"
param->length, param->iterations
/* Tests for bulk I/O using DMA mapping by core and odd address */
18bulkY--Y“TEST 18: read odd addr %d bytes %u times core map\n”,
param->length, param->iterations
-
19bulkY--Y“TEST 19: write odd addr %d bytes %u times premapped\n”,
param->length, param->iterations
/* Tests for bulk I/O using premapped coherent buffer and odd address */
20bulkY--Y“TEST 20: read odd addr %d bytes %u times premapped\n”,
param->length, param->iterations
-
21controlYY-Y“TEST 21: %d ep0out odd addr, %d…%d vary %d\n”,
param->iterations,realworld ? 1 : 0, param->length, param->vary
/* control write tests with unaligned buffer */
22isoY-YY“TEST 22: write %d iso odd, %d entries of %d bytes\n”,
param->iterations, param->sglen, param->length
/* unaligned iso tests */
23isoY-YY“TEST 23: read %d iso odd, %d entries of %d bytes\n”,
param->iterations, param->sglen, param->length
-
24bulkY-Y-“TEST 24: unlink from %d queues of %d %d-byte writes\n”,
param->iterations, param->sglen, param->length
/* unlink URBs from a bulk-OUT queue */
25intY---“TEST 25: write %d bytes %u times\n”,
param->length, param->iterations
/* Simple non-queued interrupt I/O tests */
26intY---“TEST 26: read %d bytes %u times\n”,
param->length, param->iterations
-
27bulkY-Y-“TEST 27: bulk write %dMbytes\n”,
(param->iterations * param->sglen * param->length) / (1024 * 1024))
/* Performance test */
28bulkY-Y-“TEST 28: bulk read %dMbytes\n”,
(param->iterations * param->sglen * param->length) / (1024 * 1024))
-
29bulkY---“TEST 29: Clear toggle between bulk writes %d times\n”,
param->iterations
/* Test data Toggle/seq_nr clear between bulk out transfers */

3.2 ioctl

usbtest.ko 以 ioctl 的形式向用户态提供对 testcase 的调用:

usbdev_file_operations → usbdev_ioctl() → usbdev_do_ioctl() → proc_ioctl_default() → proc_ioctl():

static int proc_ioctl(struct usb_dev_state *ps, struct usbdevfs_ioctl *ctl)
{

    /*  (1) 找到对应的 usb interface device */
	else if (!(intf = usb_ifnum_to_if(ps->dev, ctl->ifno)))
		retval = -EINVAL;

	/* talk directly to the interface's driver */
	default:
		if (intf->dev.driver)
            /*  (2) 找到 usb interface device 对应的 driver  */
			driver = to_usb_driver(intf->dev.driver);
		if (driver == NULL || driver->unlocked_ioctl == NULL) {
			retval = -ENOTTY;
		} else {
            /* (3) 调用 driver 的 ioctl 函数 */
			retval = driver->unlocked_ioctl(intf, ctl->ioctl_code, buf);
			if (retval == -ENOIOCTLCMD)
				retval = -ENOTTY;
		}

}

↓

usbtest_ioctl() → usbtest_do_ioctl()

4. App (testusb)

因为通过 ioctl 可以调用 usbtest.ko 的 testcase,所以只要一个用户态的程序通过打开 /proc/bus/usb/devices/xxxx 对应 gadget zerousb interface device 的文件节点,就可以很方便的调用测试了。

在 USB Testing on Linux 有一个现成的工程,提供了 testusb.c 和 test.sh,但是因为适配的内核比较老,所以需要对 testusb.c 进行一些修改:

-       if ((c = open ("/proc/bus/usb/devices", O_RDONLY)) < 0) {
+       if ((c = open ("/sys/kernel/debug/usb/devices", O_RDONLY)) < 0) {
                fputs ("usbfs files are missing\n", stderr);
                return -1;
        }
 
        /* collect and list the test devices */
-       if (ftw ("/proc/bus/usb", find_testdev, 3) != 0) {
+       if (ftw ("/dev/bus/usb", find_testdev, 3) != 0) {
                fputs ("ftw failed; is usbfs missing?\n", stderr);
                return -1;
        }

简单编译:

gcc -Wall -g -lpthread -o testusb testusb.c

就可以启动测试了:

$ sudo ./testusb -a
unknown speed	/dev/bus/usb/001/002
/dev/bus/usb/001/002 test 0,    0.000011 secs
/dev/bus/usb/001/002 test 1,    1.625031 secs
/dev/bus/usb/001/002 test 2 --> 110 (Connection timed out)
/dev/bus/usb/001/002 test 3,    1.639717 secs
/dev/bus/usb/001/002 test 4 --> 110 (Connection timed out)
/dev/bus/usb/001/002 test 5,    1.915198 secs
/dev/bus/usb/001/002 test 6 --> 110 (Connection timed out)
/dev/bus/usb/001/002 test 7,    1.928419 secs
/dev/bus/usb/001/002 test 8 --> 110 (Connection timed out)
/dev/bus/usb/001/002 test 9,   13.835084 secs

sudo ./testusb -a

sudo ./testusb -a -t1 -c1 -s512 -g32 -v32

sudo ./testusb -a -t29 -c1 -s512 -g32 -v32

// test 10 需要特别注意,容易挂死 host
sudo ./testusb -a -t10 -c1 -s512 -g5 -v32
// test 28 需要特别注意,容易挂死 host
sudo ./testusb -a -t28 -c1 -s512 -g32 -v32

参考资料

1.USB Testing on Linux
2.Linux USB测试
3.linux usb_gadget:设备控制器驱动测试
4.Linux-USB Gadget : Part 5: 测试 PXA UDC 驱动
5.Linux-USB Gadget : Part 4: 最简单的 gadget驱动:g_zero
6.Linux USB tests using Gadget Zero driver
7.USB/Linux USB Layers/Configfs Composite Gadget/Usage eq. to g zero.ko
8.usb/gadget: the start of the configfs interface

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux usb 6. HC/UDC 测试 的相关文章

  • 在 .gitconfig 中隐藏 GitHub 令牌

    我想将所有点文件存储在 GitHub 上 包括 gitconfig 这需要我将 GitHub 令牌隐藏在 gitconfig 中 为此 我有一个 gitconfig hidden token 文件 这是我打算编辑并放在隐藏令牌的 git 下
  • 在centos中安装sqlite3 dev和其他包

    我正在尝试使用 cpanel 在 centos 机器上安装 sqlite dev 和其他库 以便能够编译应用程序 我对 debian 比 centos 更熟悉 我知道我需要的库是 libsqlite3 dev libkrb5 dev lib
  • 就分页分段内存而言的程序寿命

    我对 x86 Linux 机器中的分段和分页过程有一个令人困惑的概念 如果有人能澄清从开始到结束所涉及的所有步骤 我们将很高兴 x86 使用分页分段内存技术进行内存管理 任何人都可以解释一下从可执行的 elf 格式文件从硬盘加载到主内存到它
  • 如何在 Ubuntu 中创建公共 HTML 文件夹?

    简单的问题 但由于某种原因我无法在谷歌上找到确切的答案 我在 Slicehost 上安装了全新的 Ubuntu 并且想在我的主目录中为包含一堆静态 HTML 文件的简单网站创建一个公共目录 我该怎么做呢 只是打字的问题吗mkdir publ
  • 执行“minikube start”命令时出现问题

    malik malik minikube start minikube v1 12 0 on Ubuntu 18 04 Using the docker driver based on existing profile Starting c
  • 如何阻止ubuntu在使用apt安装或更新软件包时弹出“Daemons using outdatedlibraries”? [关闭]

    Closed 这个问题是与编程或软件开发无关 help closed questions 目前不接受答案 我最近新安装了 Ubuntu 22 04 LTS 我发现每次使用 apt 安装或更新软件包时 它都会询问我有关Which servic
  • GMail 421 4.7.0 稍后重试,关闭连接

    我试图找出为什么它无法使用 GMail 从我的服务器发送邮件 为此 我使用 SwiftMailer 但我可以将问题包含在以下独立代码中
  • 如何根据标签将单个 XML 文件拆分为多个

    我有一个带有标签的 XML 文件 我想像这样分割文件
  • 使用循环在 C 中管道传输两个或多个 shell 命令

    我正在尝试执行ls wc l通过 C 语言程序 而不是使用命令行 这是我当前的工作代码 int main int pfds 2 pipe pfds pid t pid fork if pid 0 The child process clos
  • 添加文件时运行 shell 命令

    我的 Linux 机器上有一个名为 images 的文件夹 该文件夹连接到一个网站 该网站的管理员可以向该网站添加图片 但是 当添加图片时 我想要一个命令来运行调整目录中所有图片的大小 简而言之 我想知道当新文件添加到特定位置时如何使服务器
  • 如何获取 (Linux) 机器的 IP 地址?

    这个问题和之前问的几乎一样如何获取本地计算机的IP地址 https stackoverflow com questions 122208 get the ip address of local computer 问题 但是我需要找到一个的I
  • 并行运行 shell 脚本

    我有一个 shell 脚本 打乱大型文本文件 600 万行和 6 列 根据第一列对文件进行排序 输出 1000 个文件 所以伪代码看起来像这样 file1 sh bin bash for i in seq 1 1000 do Generat
  • 从 Xlib 转换为 xcb

    我目前正在将我的一个应用程序从 Xlib 移植到 libxcb 但在查找有关我有时使用的 XInput2 扩展的信息时遇到了一些麻烦 libxcb 中有 XInput2 实现吗 如果是的话 在哪里可以找到文档 目前我在使用此功能时遇到问题
  • 为什么opencv videowriter这么慢?

    你好 stackoverflow 社区 我有一个棘手的问题 我需要你的帮助来了解这里发生了什么 我的程序从视频采集卡 Blackmagic 捕获帧 到目前为止 它工作得很好 同时我用 opencv cv imshow 显示捕获的图像 它也工
  • 使用 python 脚本更改 shell 中的工作目录

    我想实现一个用户态命令 它将采用其参数之一 路径 并将目录更改为该目录 程序完成后 我希望 shell 位于该目录中 所以我想实施cd命令 但需要外部程序 可以在 python 脚本中完成还是我必须编写 bash 包装器 Example t
  • Linux 为一组进程保留一个处理器(动态)

    有没有办法将处理器排除在正常调度之外 也就是说 使用sched setaffinity我可以指示线程应该在哪个处理器上运行 但我正在寻找相反的情况 也就是说 我想从正常调度中排除给定的处理器 以便只有已明确调度的进程才能在那里运行 我还知道
  • ansible unarchive 模块如何查找 tar 二进制文件?

    我正在尝试执行一个 ansible 剧本 该剧本的任务是利用unarchive模块 因为我是在 OSX 上执行此操作 所以我需要使用它gnu tar 而不是bsd tar通常与 OSX 一起提供 因为BSD tar 不受官方支持 https
  • Linux下显卡内存使用情况

    Linux下有哪些工具可以监控显卡内存使用情况 NVIDIA 性能套件 http developer nvidia com content nvidia perfkit有Linux版本 可以实时监控各种显卡属性 包括显卡内存使用情况 显然
  • 为什么 XRecordDisableContext() 不起作用?

    void Callback XPointer XRecordInterceptData pRecord std cout lt lt my logs n int main if auto const pDisplay XOpenDispla
  • 具有多处理功能的 Python 代码无法在 Windows 上运行

    以下简单的绝对初学者代码在 Ubuntu 14 04 Python 2 7 6 和 Cygwin Python 2 7 8 上运行 100 但在 Windows 64 位 Python 2 7 8 上挂起 我使用另一个片段观察到了同样的情况

随机推荐

  • 每次在boot下建立ssh空文件就会被删掉,wpa_supplicant.conf 文件也会自动被删除,为什么?

    A 开启ssh 和 配置WiFi 注意2 xff1a 我知道你可能没有路由器 xff0c 你也可以用电脑开启WiFi热点 xff0c 然后在热点管理那里找到你树莓派的IP地址 如果你没有给树莓派现在就连接屏幕的想法 xff0c 第一次启动O
  • Jetson查看JetPack版本(tool)

    Jetson查看JetPack版本 查看L4T版本 我的L4T版本为 32 5 1 在官网查找对应的jetpack版本 This page includes access to previously released versions of
  • ros中设置Global Options,以及rqt_tf_tree树讲解,TF树的理解,使用GUI插件,用于可视化ROS-TF的框架树

    一 设置Global Options 如图30 启动rviz界面后 首先要对Global Options进行设置 Global Options里面的参数是一些全局显示相关的参数 其中的Fixed Frame参数是全局显示区域依托的坐标系 我
  • jetson xavier和NX 以及nano如何通过sd卡启动,sdkManager刷机

    1 xff0c xavier可以通过迁移系统的方法进行 Jetson AGX Xavier从SD卡启动系统及系统移植 xavier AGX不能直接使用sdkManager刷机到SD卡 xff0c 所以需要用系统迁移的方法 2 xff0c N
  • Linux NameSpace (目录)

    1 User Namespace 详解 2 Pid Namespace 详解 3 Mnt Namespace 详解 4 UTS Namespace 详解 5 IPC Namespace 详解 6 Network Namespace 详解
  • Python Nose 自动化测试框架介绍

    文章目录 1 unittest 简介1 1 python 单元测试1 2 unittest 测试框架1 3 默认模式1 4 手工模式 2 nose 扩展框架2 1 96 nose 96 的安装和基本用法2 2 96 被测对象 96 的扩展2
  • TLSF 内存分配算法详解

    文章目录 1 DSA 背景介绍1 1 mmheap1 2 mmblk 2 TLSF 原理2 1 存储结构2 2 内存池初始化2 3 free2 4 malloc 参考资料 1 DSA 背景介绍 动态内存管理算法 DSA xff0c Dyna
  • 史上最全采样方法详细解读与代码实现

    项目github地址 xff1a bitcarmanlee easy algorithm interview and practice 欢迎大家star xff0c 留言 xff0c 一起学习进步 1 什么是采样 在信号系统 数字信号处理中
  • Linux Kdump 机制详解

    文章目录 1 简介1 1 安装1 2 触发 kdump1 3 调试 kdump1 3 1 安装 debuginfo vmlinux1 3 2 编译 kernel 1 4 kdump tools service 流程分析 2 原理分析2 1
  • Buildroot 用户手册 (中文)

    文章目录 I Getting started1 About Buildroot2 System requirements2 1 Mandatory packages2 2 Optional packages 3 Getting Buildr
  • 正则表达式 (学习笔记)

    正则表达式的难度不在于难懂 xff0c 而在于对它的表述没有恰当的分类和组织 xff0c 所以弄得很零散难以记忆 按照自己的理解和归纳记录一份笔记 xff0c 以备遗忘时查看 正则表达式 regular expressions 是一种用来匹
  • Linux usb 2. 协议分析

    文章目录 0 背景1 USB 协议传输格式1 1 Packet1 1 1 Token Packet1 1 2 Data Packet1 1 3 Handshake Packet1 1 4 Special Packet 1 2 Transac
  • RISCV 入门 (学习笔记)

    文章目录 1 risv 相关背景1 1 arm 授权费1 2 riscv 发展历史1 3 riscv 风险 2 指令集2 1 可配置的通用寄存器组2 2 规整的指令编码2 3 简洁的存储器访问指令2 4 高效的分支跳转指令2 5 简洁的子程
  • Linux usb 1. 总线简介

    文章目录 1 USB 发展历史1 1 USB 1 0 2 01 2 USB 3 01 3 速度识别1 4 OTG1 5 phy 总线1 6 传输编码方式 2 总线拓扑2 1 Device 内部的逻辑关系2 2 Compound Compos
  • Linux usb 3. Host 详解

    文章目录 1 简介2 Usb Core 驱动设备模型2 1 Usb Device Layer2 1 1 device struct usb device 2 1 2 driver struct usb device driver 2 1 3
  • Linux usb 4. Device 详解

    文章目录 1 简介2 Platform Layer2 1 Platform Device2 2 Platform Driver 3 UDC Gadget Layer3 1 Gadget Bus3 2 Gadget Device3 2 1 E
  • Linux USB (目录)

    1 USB 总线简介 2 USB 协议分析 3 USB Host 详解 4 USB Device 详解 5 usbip USB Over IP 使用实例 6 USB HC UDC 测试 7 Linux 配置 ADBD
  • Linux usb 5. usbip (USB Over IP) 使用实例

    文章目录 0 简介1 Server 配置2 Client 配置参考资料 0 简介 USB Over IP 是一种应用很多的场景 xff0c 目前已经有现成的解决方案 usbip linux 和 windows 环境下都有配套软件 xff0c
  • 最全随机抽样算法(从N个数中抽取M个等)集合

    项目github地址 xff1a bitcarmanlee easy algorithm interview and practice 欢迎大家star xff0c 留言 xff0c 一起学习进步 1 从N个数中等概率抽取M个数 从N个样本
  • Linux usb 6. HC/UDC 测试

    文章目录 1 背景介绍2 Device gadget zero 2 1 96 gadget zero 96 创建2 2 SourceSink Function2 3 Loopback Function 3 Host usbtest ko 3