QEMU源码全解析 —— virtio(9)

接前一篇文章:

上两回讲解了virtio balloon相关类所涉及的realize函数以及大致流程,如下表所示:

realize函数parent_dc_realize函数
DeviceClassvirtio_pci_dc_realize
PCIDeviceClassvirtio_pci_realize
VirtioPCIClassvirtio_balloon_pci_realizepci_qdev_realize

本回对于流程进行深入解析。

综合前文书所讲,当具现化TYPE_VIRTIO_BALLOON的时候,device_set_realized函数中会首先调用DeciceClass->realize即virtio_pci_dc_realize函数。再次贴出该函数源码,在hw/virtio/virtio-pci.c中,如下:

static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
{VirtioPCIClass *vpciklass = VIRTIO_PCI_GET_CLASS(qdev);VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);PCIDevice *pci_dev = &proxy->pci_dev;if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) &&virtio_pci_modern(proxy)) {pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;}vpciklass->parent_dc_realize(qdev, errp);
}

virtio_pci_dc_realize函数首先判断virtio PCI代理设备是否具有VIRTIO_PCI_FLAG_DISABLE_PCIE特性,该特性使得virtio PCI代理展现出PCIe的的接口。

然后调用了vpciklass->parent_dc_realize函数,由前文分析可知,该回调函数是pci_qdev_realize()。再次贴出pci_qdev_realize函数源码,在hw/virtio/virtio-pci.c中,如下:

static void pci_qdev_realize(DeviceState *qdev, Error **errp)
{PCIDevice *pci_dev = (PCIDevice *)qdev;PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);ObjectClass *klass = OBJECT_CLASS(pc);Error *local_err = NULL;bool is_default_rom;uint16_t class_id;/** capped by systemd (see: udev-builtin-net_id.c)* as it's the only known user honor it to avoid users* misconfigure QEMU and then wonder why acpi-index doesn't work*/if (pci_dev->acpi_index > ONBOARD_INDEX_MAX) {error_setg(errp, "acpi-index should be less or equal to %u",ONBOARD_INDEX_MAX);return;}/** make sure that acpi-index is unique across all present PCI devices*/if (pci_dev->acpi_index) {GSequence *used_indexes = pci_acpi_index_list();if (g_sequence_lookup(used_indexes,GINT_TO_POINTER(pci_dev->acpi_index),g_cmp_uint32, NULL)) {error_setg(errp, "a PCI device with acpi-index = %" PRIu32" already exist", pci_dev->acpi_index);return;}g_sequence_insert_sorted(used_indexes,GINT_TO_POINTER(pci_dev->acpi_index),g_cmp_uint32, NULL);}if (pci_dev->romsize != -1 && !is_power_of_2(pci_dev->romsize)) {error_setg(errp, "ROM size %u is not a power of two", pci_dev->romsize);return;}/* initialize cap_present for pci_is_express() and pci_config_size(),* Note that hybrid PCIs are not set automatically and need to manage* QEMU_PCI_CAP_EXPRESS manually */if (object_class_dynamic_cast(klass, INTERFACE_PCIE_DEVICE) &&!object_class_dynamic_cast(klass, INTERFACE_CONVENTIONAL_PCI_DEVICE)) {pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;}if (object_class_dynamic_cast(klass, INTERFACE_CXL_DEVICE)) {pci_dev->cap_present |= QEMU_PCIE_CAP_CXL;}pci_dev = do_pci_register_device(pci_dev,object_get_typename(OBJECT(qdev)),pci_dev->devfn, errp);if (pci_dev == NULL)return;if (pc->realize) {pc->realize(pci_dev, &local_err);if (local_err) {error_propagate(errp, local_err);do_pci_unregister_device(pci_dev);return;}}/** A PCIe Downstream Port that do not have ARI Forwarding enabled must* associate only Device 0 with the device attached to the bus* representing the Link from the Port (PCIe base spec rev 4.0 ver 0.3,* sec 7.3.1).* With ARI, PCI_SLOT() can return non-zero value as the traditional* 5-bit Device Number and 3-bit Function Number fields in its associated* Routing IDs, Requester IDs and Completer IDs are interpreted as a* single 8-bit Function Number. Hence, ignore ARI capable devices.*/if (pci_is_express(pci_dev) &&!pcie_find_capability(pci_dev, PCI_EXT_CAP_ID_ARI) &&pcie_has_upstream_port(pci_dev) &&PCI_SLOT(pci_dev->devfn)) {warn_report("PCI: slot %d is not valid for %s,"" parent device only allows plugging into slot 0.",PCI_SLOT(pci_dev->devfn), pci_dev->name);}if (pci_dev->failover_pair_id) {if (!pci_bus_is_express(pci_get_bus(pci_dev))) {error_setg(errp, "failover primary device must be on ""PCIExpress bus");pci_qdev_unrealize(DEVICE(pci_dev));return;}class_id = pci_get_word(pci_dev->config + PCI_CLASS_DEVICE);if (class_id != PCI_CLASS_NETWORK_ETHERNET) {error_setg(errp, "failover primary device is not an ""Ethernet device");pci_qdev_unrealize(DEVICE(pci_dev));return;}if ((pci_dev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION)|| (PCI_FUNC(pci_dev->devfn) != 0)) {error_setg(errp, "failover: primary device must be in its own ""PCI slot");pci_qdev_unrealize(DEVICE(pci_dev));return;}qdev->allow_unplug_during_migration = true;}/* rom loading */is_default_rom = false;if (pci_dev->romfile == NULL && pc->romfile != NULL) {pci_dev->romfile = g_strdup(pc->romfile);is_default_rom = true;}pci_add_option_rom(pci_dev, is_default_rom, &local_err);if (local_err) {error_propagate(errp, local_err);pci_qdev_unrealize(DEVICE(pci_dev));return;}pci_set_power(pci_dev, true);pci_dev->msi_trigger = pci_msi_trigger;
}

pci_qdev_realize函数会将virtioPCI代理设备注册到PCI总线上,并调用PCIDeviceClass->realize函数指针所指向的函数,也就是virtio_pci_realize函数。代码片段如下:

    pci_dev = do_pci_register_device(pci_dev,object_get_typename(OBJECT(qdev)),pci_dev->devfn, errp);if (pci_dev == NULL)return;if (pc->realize) {pc->realize(pci_dev, &local_err);if (local_err) {error_propagate(errp, local_err);do_pci_unregister_device(pci_dev);return;}}

virtio_pci_realize函数在hw/virtio/virtio-pci.c中,代码如下:

static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
{VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev);bool pcie_port = pci_bus_is_express(pci_get_bus(pci_dev)) &&!pci_bus_is_root(pci_get_bus(pci_dev));if (kvm_enabled() && !kvm_has_many_ioeventfds()) {proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;}/* fd-based ioevents can't be synchronized in record/replay */if (replay_mode != REPLAY_MODE_NONE) {proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;}/** virtio pci bar layout used by default.* subclasses can re-arrange things if needed.**   region 0   --  virtio legacy io bar*   region 1   --  msi-x bar*   region 2   --  virtio modern io bar (off by default)*   region 4+5 --  virtio modern memory (64bit) bar**/proxy->legacy_io_bar_idx  = 0;proxy->msix_bar_idx       = 1;proxy->modern_io_bar_idx  = 2;proxy->modern_mem_bar_idx = 4;proxy->common.offset = 0x0;proxy->common.size = 0x1000;proxy->common.type = VIRTIO_PCI_CAP_COMMON_CFG;proxy->isr.offset = 0x1000;proxy->isr.size = 0x1000;proxy->isr.type = VIRTIO_PCI_CAP_ISR_CFG;proxy->device.offset = 0x2000;proxy->device.size = 0x1000;proxy->device.type = VIRTIO_PCI_CAP_DEVICE_CFG;proxy->notify.offset = 0x3000;proxy->notify.size = virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MAX;proxy->notify.type = VIRTIO_PCI_CAP_NOTIFY_CFG;proxy->notify_pio.offset = 0x0;proxy->notify_pio.size = 0x4;proxy->notify_pio.type = VIRTIO_PCI_CAP_NOTIFY_CFG;/* subclasses can enforce modern, so do this unconditionally */memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci",/* PCI BAR regions must be powers of 2 */pow2ceil(proxy->notify.offset + proxy->notify.size));if (proxy->disable_legacy == ON_OFF_AUTO_AUTO) {proxy->disable_legacy = pcie_port ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;}if (!virtio_pci_modern(proxy) && !virtio_pci_legacy(proxy)) {error_setg(errp, "device cannot work as neither modern nor legacy mode"" is enabled");error_append_hint(errp, "Set either disable-modern or disable-legacy"" to off\n");return;}if (pcie_port && pci_is_express(pci_dev)) {int pos;uint16_t last_pcie_cap_offset = PCI_CONFIG_SPACE_SIZE;pos = pcie_endpoint_cap_init(pci_dev, 0);assert(pos > 0);pos = pci_add_capability(pci_dev, PCI_CAP_ID_PM, 0,PCI_PM_SIZEOF, errp);if (pos < 0) {return;}pci_dev->exp.pm_cap = pos;/** Indicates that this function complies with revision 1.2 of the* PCI Power Management Interface Specification.*/pci_set_word(pci_dev->config + pos + PCI_PM_PMC, 0x3);if (proxy->flags & VIRTIO_PCI_FLAG_AER) {pcie_aer_init(pci_dev, PCI_ERR_VER, last_pcie_cap_offset,PCI_ERR_SIZEOF, NULL);last_pcie_cap_offset += PCI_ERR_SIZEOF;}if (proxy->flags & VIRTIO_PCI_FLAG_INIT_DEVERR) {/* Init error enabling flags */pcie_cap_deverr_init(pci_dev);}if (proxy->flags & VIRTIO_PCI_FLAG_INIT_LNKCTL) {/* Init Link Control Register */pcie_cap_lnkctl_init(pci_dev);}if (proxy->flags & VIRTIO_PCI_FLAG_INIT_PM) {/* Init Power Management Control Register */pci_set_word(pci_dev->wmask + pos + PCI_PM_CTRL,PCI_PM_CTRL_STATE_MASK);}if (proxy->flags & VIRTIO_PCI_FLAG_ATS) {pcie_ats_init(pci_dev, last_pcie_cap_offset,proxy->flags & VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED);last_pcie_cap_offset += PCI_EXT_CAP_ATS_SIZEOF;}if (proxy->flags & VIRTIO_PCI_FLAG_INIT_FLR) {/* Set Function Level Reset capability bit */pcie_cap_flr_init(pci_dev);}} else {/** make future invocations of pci_is_express() return false* and pci_config_size() return PCI_CONFIG_SPACE_SIZE.*/pci_dev->cap_present &= ~QEMU_PCI_CAP_EXPRESS;}virtio_pci_bus_new(&proxy->bus, sizeof(proxy->bus), proxy);if (k->realize) {k->realize(proxy, errp);}
}

(1)virtio_pci_realize函数首先初始化virtioPCI代理设备,也就是VirtIOPCIProxy结构。代码片段如下:

    VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);

(2)然后,virtio_pci_realize函数初始化VirtIOPCIProxy设备的多个BAR数据,设置了这些BAR的索引号。代码片段如下:

    /** virtio pci bar layout used by default.* subclasses can re-arrange things if needed.**   region 0   --  virtio legacy io bar*   region 1   --  msi-x bar*   region 2   --  virtio modern io bar (off by default)*   region 4+5 --  virtio modern memory (64bit) bar**/proxy->legacy_io_bar_idx  = 0;proxy->msix_bar_idx       = 1;proxy->modern_io_bar_idx  = 2;proxy->modern_mem_bar_idx = 4;

其中:

legacy I/O地址为0;

msi-x地址为1;

modern IO地址为2;

modern MMIO地址为4。

这里的legacy和modern指的是不同的virtio版本。

(3)virtio_pci_realize函数还初始化了多个VirtIOPCIRegion(VirtIOPCIRegion用来表示virtio设备的配置空间信息),如VirtIOProxy的common、isr、device、notify成员。代码片段如下:

    proxy->common.offset = 0x0;proxy->common.size = 0x1000;proxy->common.type = VIRTIO_PCI_CAP_COMMON_CFG;proxy->isr.offset = 0x1000;proxy->isr.size = 0x1000;proxy->isr.type = VIRTIO_PCI_CAP_ISR_CFG;proxy->device.offset = 0x2000;proxy->device.size = 0x1000;proxy->device.type = VIRTIO_PCI_CAP_DEVICE_CFG;proxy->notify.offset = 0x3000;proxy->notify.size = virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MAX;proxy->notify.type = VIRTIO_PCI_CAP_NOTIFY_CFG;proxy->notify_pio.offset = 0x0;proxy->notify_pio.size = 0x4;proxy->notify_pio.type = VIRTIO_PCI_CAP_NOTIFY_CFG;

VirtIOPCIRegion保存了VirtIOPCIProxy设备modern MMIO的相关信息。如VirtIOProxy的modern MMIO中,最开始的区域是common区域,其大小为0x1000,范围是[0x0, 0x1000);接着是isr区域,大小也是0x1000,范围是[0x1000, 0x2000);然后是device区域,其大小仍然是0x1000,范围是[0x2000,0x3000);最后是notify区域,其大小是virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MAX,范围是[0x3000, 0x3000+virtio_pci_queue_mem_mult(proxy) * VIRTIO_QUEUE_MAX)。

 (4)VirtIOPCIProxy的modern MMIO对应的MemoryRegion存放在VirtIOPCIProxy的modern_bar成员中;它还有一个MemoryRegion存放在modern_cfg成员中(这部分老版本代码有,新版本代码已经没有了)。代码片段如下:

    /* subclasses can enforce modern, so do this unconditionally */memory_region_init(&proxy->modern_bar, OBJECT(proxy), "virtio-pci",/* PCI BAR regions must be powers of 2 */pow2ceil(proxy->notify.offset + proxy->notify.size));if (proxy->disable_legacy == ON_OFF_AUTO_AUTO) {proxy->disable_legacy = pcie_port ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;}if (!virtio_pci_modern(proxy) && !virtio_pci_legacy(proxy)) {error_setg(errp, "device cannot work as neither modern nor legacy mode"" is enabled");error_append_hint(errp, "Set either disable-modern or disable-legacy"" to off\n");return;}

(5)virtio_pci_realize函数会调用virtio_pci_bus_new函数创建virtio-bus,挂载到当前的virtio PCI代理设备下面。代码片段如下:

    virtio_pci_bus_new(&proxy->bus, sizeof(proxy->bus), proxy);

(6)virtio_pci_realize函数在最后调用了k->realize函数指针所指向的函数。由于k是VirtioPCIClass类型,因此根据前表

realize函数parent_dc_realize函数
DeviceClassvirtio_pci_dc_realize
PCIDeviceClassvirtio_pci_realize
VirtioPCIClassvirtio_balloon_pci_realizepci_qdev_realize

因此k->realize函数指针实际指向了virtio_balloon_pci_realize函数。

对于virtio_balloon_pci_realize函数内容的讲解,请看下回。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/225641.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Cellinx NVT 摄像机 GetFileContent.cgi任意文件读取漏洞 (CVE-2023-23063)

0x01 产品简介 Cellinx NVT IP PTZ是韩国Cellinx公司的一个摄像机设备。 0x02 漏洞概述 Cellinx NVT v1.0.6.002b版本存在安全漏洞&#xff0c;该漏洞源于存在本地文件泄露漏洞&#xff0c;攻击者可读取系统密码等敏感信息。 0x03 复现环境 FOFA&#xff1a;body"loc…

云仓酒庄带您品法国葡萄酒

说起葡萄酒肯定绕不开法国&#xff0c;法国葡萄酒闻名中外&#xff0c;口碑卓越。作为世界上的产酒大国&#xff0c;可以说是每一寸土地都可以种植葡萄。云仓酒庄的品牌雷盛红酒分享这么优秀的一个葡萄酒产酒国有哪些特点呢&#xff1f; 1.产区特色&#xff1a;波国有最著名的…

vue3 使用antd 报错Uncaught TypeError--【已解决】

问题现象 使用最基本的 ant-design-vue 按钮demo 都报错 报错文字如下 Uncaught TypeError: Cannot read properties of undefined (reading value)at ReactiveEffect.fn (ant-design-vue.js?v597f5366:6693:87)at ReactiveEffect.run (chunk-K2VKR2AM.js?v25c381c3:461:…

springboot发送邮件,内容使用thymeleaf模板引擎排版

springboot发送邮件,内容使用thymeleaf模板引擎排版 1、导入jar包2、yml设置3、收件人以及收件信息设置4、发邮件service5、模版页面6、controller 1、导入jar包 <!--发送邮件--><dependency><groupId>org.springframework.boot</groupId><artifac…

react经验7:高亮关键字

预期效果&#xff1a; 实现原理 将需要高亮的关键词做成正则表达式 new RegExp((${word}), "gi")使用上述正则表达式切割目标字符串 origin.split(new RegExp((${word}), "gi"))切割结果会包含正则匹配到的词 过滤掉空字符&#xff0c;并对关键词包裹…

人工智能与大数据的紧密联系

随着科技的飞速发展&#xff0c;人工智能&#xff08;Artificial Intelligence&#xff0c;AI&#xff09;和大数据&#xff08;Big Data&#xff09;已成为当今社会的热门话题。人工智能在许多领域的应用越来越广泛&#xff0c;而大数据则提供了支持和驱动AI技术的巨大资源。本…

原点处可微问题

文章目录 原点可微问题例例 原点可微问题 lim ⁡ x → 0 , y → 0 f ( x , y ) − f ( 0 , 0 ) x 2 y 2 \lim\limits_{x\to{0},y\to{0}} \frac{f(x,y)-f(0,0)}{\sqrt{x^2y^2}} x→0,y→0lim​x2y2 ​f(x,y)−f(0,0)​ 0 0 0(1)是函数 f ( x , y ) f(x,y) f(x,y)在 ( 0 , 0 ) (…

未来应用从何而来:认知力延伸、边界突破、回归云与产业

文 | 智能相对论 作者 | 沈浪 或许&#xff0c;谁也没想到未来应用来的如此之快&#xff0c;现如今传统应用从开发到体验&#xff0c;已经进入了一个前所未有的颠覆性改革阶段。 不久前&#xff0c;美国人工智能公司OpenAI举办开发者大会。在现场&#xff0c;公司创始人Sam …

BearPi Std 板从入门到放弃 - 先天神魂篇(6)(RT-Thread 按键中断响应)

简介 使用BearPi IOT Std开发板及主板自带两颗按键与用户灯, 实现按键触发中断控制灯亮灯灭 主板: 主芯片: STM32L431RCT6 LED : PC13 \ 推挽输出\ 高电平点亮 串口: Usart1 KEY1 : PB2 \ 上拉 \ 按下下降沿触发(一次)/上下沿触发(两次&#xff0c;实现按下开、松开关) KEY2 :…

网络安全项目实战(无)--报文检测

10. TFTP 应用协议报文解析 目标 了解tftp协议了解tftp基本操作方式&#xff08;put/get&#xff09;了解tftp协议探测方法&#xff08;简洁&#xff09; 10.1. tftp 基本操作 通过操作tftp client和server操作&#xff0c; 熟悉抓包流程 10.1.1. Server 端 安装服务 itcas…

FIFO的Verilog设计(三)——最小深度计算

文章目录 前言一、FIFO的最小深度写速度快于读速度写速度等于或慢于读速度 二、 举例说明1. FIFO写时钟为100MHz&#xff0c;读时钟为80Mhz情况一&#xff1a;一共需要传输2000个数据&#xff0c;求FIFO的最小深度情况二&#xff1a;100个时钟写入80个数据&#xff0c;1个时钟读…

PostgreSQL向量数据插件--pgvector安装(附PostgreSQL安装)

PostgreSQL向量数据插件--pgvector安装 一、版本二、数据库安装1. 在官网下载PostgreSQL14.0的安装包2.增加用户postgres3.解压安装 三、pgvector安装1. 从github上克隆下来2. 安装pgvector插件3. 开始使用pgvector启用pgsql命令行创建扩展 本文为本人在安装pgvector中踩过的坑…

Windows安装卸载MySQL

【官方】MySQL参考手册&#xff1a;介绍MySQL Server、SQL、InnoDB存储引擎、复制等。 Windows 卸载 MySQL 删除程序 【win x】 > p &#xff0c;在安装的程序中卸载MySQL相关删除安装目录和数据文件夹 D:\ProgramFiles\MySQL C:\ProgramData\MySQL删除服务 【win r】 &…

ElasticSearch之cat segments API

命令样例如下&#xff1a; curl -X GET "https://localhost:9200/_cat/segments?vtrue&pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPHQBEs5*lo7F9"执行结果输出如下&#xff1a; index shard prirep ip segment g…

25 redis 中 cluster 集群的工作模式

前言 我们这里首先来看 redis 这边实现比较复杂的 cluster集群模式 整个 cluster集群 中会包含多对 MasterSlave 的组合, 然后这多对 MasterSlave 来分解 16384 个 slot 然后 客户端这边 set, get 的时候, 先根据 key 计算对应存储的 slot, 然后 服务器这边响应 MOVED 目标…

P with Spacy:自定义文本分类管道

一、说明 Spacy 是一个功能强大的 NLP 库&#xff0c;其中许多 NLP 任务&#xff08;如标记化、词干提取、词性标记和命名实体解析&#xff09;均通过预训练模型提供开箱即用的功能。所有这些任务都由管道对象以及逐步应用于给定文本的不同函数的内部抽象来包装。该管道可以通过…

Android--UML类图使用详解

明敕星驰封宝剑&#xff0c;辞君一夜取楼兰 一&#xff0c;定义 类图(Class diagram)是显示了模型的静态结构&#xff0c;特别是模型中存在的类、类的内部结构以及它们与其他类的关系等。类图不显示暂时性的信息。类图是面向对象建模的主要组成部分。它既用于应用程序的系统分…

【数字电路】MacBook使用iverilog进行数字电路仿真

安装流程 在终端中用brew包管理工具进行安装仿真工具&#xff1a; 编译verilog代码&#xff1a; brew install icarus-verilog编译verilog代码&#xff1a; brew install verilatorMacOS系统显示UNIX GUI brew install xquartz可视化仿真波形图&#xff1a; brew install gtk…

基于Springboot的任务发布平台设计与实现(源码齐全+调试)

项目描述 临近学期结束&#xff0c;还是毕业设计&#xff0c;你还在做java程序网络编程&#xff0c;期末作业&#xff0c;老师的作业要求觉得大了吗?不知道毕业设计该怎么办?网页功能的数量是否太多?没有合适的类型或系统?等等。你想解决的问题&#xff0c;今天给大家介绍…

t-io 程序执行后,jvm不退出的原因

基于t-io 1.7.3 版本分析源码 1、设定当前时间&#xff0c;每10毫秒执行一次 (非守护线程) 2、对应线程池的核心线程在AioServer启动时全部激活&#xff0c;并且添加空任务到阻塞队列&#xff0c;让核心线程(非守护线程)一直存活