当前位置: 首页 > news >正文

厚街外贸网站建设今日足球最新预测比分

厚街外贸网站建设,今日足球最新预测比分,宁波房产网上备案查询官网,宽带维修诉求:遇到一个问题 echo blocked > /sys/class/block/sdb/device/state 报非法参数,想要知道根因,但是对这块内核代码不熟悉,不知道从哪里下手,那就先用ftrace看看内核调用栈,如下所示。 rootrlk:/home…

诉求:遇到一个问题 echo blocked > /sys/class/block/sdb/device/state 报非法参数,想要知道根因,但是对这块内核代码不熟悉,不知道从哪里下手,那就先用ftrace看看内核调用栈,如下所示。

root@rlk:/home/rlk/rlk# echo blocked > /sys/class/block/sdb/device/state
bash: echo: write error: Invalid argument

cd /sys/kernel/debug/tracing

  • 设定跟踪的进程pid
    set_ftrace_pid

  • 查看可以设定的tracer

root@rlk:/home/rlk/rlk# cat /sys/kernel/debug/tracing/available_tracers
hwlat blk mmiotrace function_graph wakeup_dl wakeup_rt wakeup function nop
  • 设定tracer类型
root@rlk:/sys/kernel/debug/tracing# echo function_graph > current_tracer
  • 开启tracer
root@rlk:/sys/kernel/debug/tracing# echo 1 > tracing_on

写文件/sys/class/block/sdb/device/state是一个很快的过程,没有办法精准的知道什么时候把trace打开,所以只能采集相对来说比较泛的数据,为了减少一些无用的数据,可以通过写两个脚本来实现,先抓取echo running > /sys/class/block/sdb/device/state的调用栈。

write.sh

#!/bin/bash
sleep 0.3
echo running > /sys/class/block/sdb/device/state

查找进程pid命令花费的时间为0.109s

root@rlk:/home/rlk/rlk# time ps aux | grep write.sh | grep -v grep | awk '{print $2}'
5442real    0m0.109s
user    0m0.019s
sys     0m0.121s
#!/bin/bash
./write.sh &
pid=`ps aux | grep write.sh | grep -v grep | awk '{print $2}'`
echo $pidecho $pid > /sys/kernel/debug/tracing/set_ftrace_pid
echo 1 > /sys/kernel/debug/tracing/tracing_on

echo 其实就是一个打开文件,然后写文件的过程,用户态写文件会调用vfs_write,在trace日志中抓出如下调用信息。

 1)               |  do_syscall_64() {1)               |    __x64_sys_write() {1)               |      ksys_write() {1)               |        __fdget_pos() {1)   0.100 us    |          __fget_light();1)   0.291 us    |        }1)               |        vfs_write() {1)               |          rw_verify_area() {1)               |            security_file_permission() {1)               |              apparmor_file_permission() {1)               |                common_file_perm() {1)   0.100 us    |                  aa_file_perm();1)   0.290 us    |                }1)   0.481 us    |              }1)   0.682 us    |            }1)   0.872 us    |          }1)               |          __sb_start_write() {1)               |            _cond_resched() {1)   0.090 us    |              rcu_all_qs();1)   0.271 us    |            }1)   0.461 us    |          }1)               |          __vfs_write() {1)               |            kernfs_fop_write() {1)               |              __kmalloc() {1)   0.090 us    |                kmalloc_slab();1)               |                _cond_resched() {1)   0.091 us    |                  rcu_all_qs();1)   0.291 us    |                }1)   0.090 us    |                should_failslab();1)   0.330 us    |                memcg_kmem_put_cache();1)   1.513 us    |              }1)               |              __check_object_size() {1)   0.100 us    |                check_stack_object();1)   0.090 us    |                __virt_addr_valid();1)   0.491 us    |                __check_heap_object();1)   1.202 us    |              }1)               |              mutex_lock() {1)               |                _cond_resched() {1)   0.090 us    |                  rcu_all_qs();1)   0.261 us    |                }1)   0.451 us    |              }1)   0.090 us    |              kernfs_get_active();1)               |              sysfs_kf_write() {	//调用sfsfs写接口1)               |                dev_attr_store() {1)               |                  store_state_field() {1)               |                    mutex_lock() {1)               |                      _cond_resched() {1)   0.100 us    |                        rcu_all_qs();1)   0.271 us    |                      }1)   0.461 us    |                    }1)   0.200 us    |                    scsi_device_set_state(); //在这里设置了device的状态1)               |                    blk_mq_run_hw_queues() {1)               |                      blk_mq_run_hw_queue() {1)   0.390 us    |                        dd_has_work();1)   2.084 us    |                      }1)   2.775 us    |                    }1)   0.090 us    |                    mutex_unlock();1)   4.628 us    |                  }1)   5.210 us    |                }1)   6.191 us    |              }1)   0.101 us    |              kernfs_put_active();1)   0.090 us    |              mutex_unlock();1)   0.091 us    |              kfree();1) + 10.841 us   |            }1) + 11.071 us   |          }1)   0.091 us    |              kfree();1) + 10.841 us   |            }1) + 11.071 us   |          }1)   0.090 us    |          __fsnotify_parent();1)   0.090 us    |          fsnotify();1)   0.080 us    |          __sb_end_write();1) + 13.415 us   |        }1) + 14.006 us   |      }1) + 14.187 us   |    }1)   0.090 us    |    fpregs_assert_state_consistent();1) + 14.627 us   |  }

drivers/scsi/scsi_sysfs.c定义了 /sys/class/block/sdx/device/state操作函数,所有块设备相关(ll /sys/class/block/sdx/device/)DEVICE_ATTR都可以在这个文件中找到,测试的内核版本为5.4.0-26-generic


// 
static const struct {enum scsi_host_state	value;char			*name;
} shost_states[] = {{ SHOST_CREATED, "created" },{ SHOST_RUNNING, "running" },{ SHOST_CANCEL, "cancel" },{ SHOST_DEL, "deleted" },{ SHOST_RECOVERY, "recovery" },{ SHOST_CANCEL_RECOVERY, "cancel/recovery" },{ SHOST_DEL_RECOVERY, "deleted/recovery", },
};
const char *scsi_host_state_name(enum scsi_host_state state)
{int i;char *name = NULL;for (i = 0; i < ARRAY_SIZE(shost_states); i++) {if (shost_states[i].value == state) {name = shost_states[i].name;break;}}return name;
}static ssize_t
store_state_field(struct device *dev, struct device_attribute *attr,const char *buf, size_t count)
{int i, ret;struct scsi_device *sdev = to_scsi_device(dev);enum scsi_device_state state = 0;for (i = 0; i < ARRAY_SIZE(sdev_states); i++) {const int len = strlen(sdev_states[i].name);if (strncmp(sdev_states[i].name, buf, len) == 0 &&buf[len] == '\n') {state = sdev_states[i].value;break;}}switch (state) {case SDEV_RUNNING:case SDEV_OFFLINE:break;default:return -EINVAL;}mutex_lock(&sdev->state_mutex);ret = scsi_device_set_state(sdev, state);/** If the device state changes to SDEV_RUNNING, we need to run* the queue to avoid I/O hang.*/if (ret == 0 && state == SDEV_RUNNING)blk_mq_run_hw_queues(sdev->request_queue, true);mutex_unlock(&sdev->state_mutex);return ret == 0 ? count : -EINVAL;
}static ssize_t
show_state_field(struct device *dev, struct device_attribute *attr, char *buf)
{struct scsi_device *sdev = to_scsi_device(dev);const char *name = scsi_device_state_name(sdev->sdev_state);if (!name)return -EINVAL;return snprintf(buf, 20, "%s\n", name);
}static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_state_field, store_state_field);

以上问题可以在上面的代码找到答案,当前仅支持设置SDEV_RUNNING,SDEV_OFFLINE两种状态。

DEVICE_ATTR 是一个宏定义,用于在 Linux 设备驱动程序中定义设备属性。它定义了一个名为 dev_attr_ 的静态结构体变量,其中 是属性的名称。该结构体包含了属性的名称、读取和写入函数的指针,以及一些其他属性。

使用 DEVICE_ATTR 宏可以方便地定义设备属性,而无需手动编写结构体和函数。例如,以下代码定义了一个名为 my_attribute 的设备属性:

static ssize_t my_attribute_show(struct device *dev, struct device_attribute *attr, char *buf)
{// 读取属性值并将其写入缓冲区return sprintf(buf, "Hello, world!\n");
}static ssize_t my_attribute_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{// 将缓冲区中的值写入属性return count;
}DEVICE_ATTR(my_attribute, 0644, my_attribute_show, my_attribute_store);

在上面的代码中,my_attribute_show 和 my_attribute_store 分别是读取和写入函数的指针。0644 是属性的访问权限,表示该属性可以被所有者读取和写入,其他用户只能读取。最后一行使用 DEVICE_ATTR 宏定义了 my_attribute 属性。

Linux 内核的 IO 调用栈通常包括以下几个层次:

用户空间调用:应用程序通过系统调用(如 read、write、open 等)向内核发起 IO 请求。

VFS 层:VFS(Virtual File System)是 Linux 内核中的一个抽象层,它负责管理文件系统的挂载、卸载、文件名解析等操作。当应用程序发起 IO 请求时,VFS 层会根据文件系统类型和文件描述符等信息,将请求转发给相应的文件系统。

文件系统层:文件系统层负责具体的 IO 操作,包括读写磁盘、缓存管理、文件系统元数据更新等。不同的文件系统有不同的实现方式,但它们都需要遵循 VFS 层的接口规范。

块设备层:块设备层负责将 IO 请求转换为磁盘操作。它通过与硬件驱动程序的交互,将数据从内核缓冲区写入磁盘或从磁盘读取数据到内核缓冲区。

硬件驱动程序:硬件驱动程序负责与硬件设备进行通信,将 IO 请求转换为硬件操作。它通过与设备控制器的交互,将数据从内存写入磁盘或从磁盘读取数据到内存。

总的来说,Linux 内核的 IO 调用栈是一个由多个层次组成的复杂系统,每个层次都有自己的职责和实现方式。在 IO 请求的处理过程中,数据需要在不同的层次之间传递和转换,因此 IO 性能的优化需要考虑整个调用栈的影响。


文章转载自:
http://dinncoextenuating.tpps.cn
http://dinncoballistically.tpps.cn
http://dinncodialysis.tpps.cn
http://dinncobeater.tpps.cn
http://dinncokibbitz.tpps.cn
http://dinncounavoidably.tpps.cn
http://dinncovitalise.tpps.cn
http://dinncoablate.tpps.cn
http://dinncohyalite.tpps.cn
http://dinncocommutativity.tpps.cn
http://dinncoexemplum.tpps.cn
http://dinncogriffith.tpps.cn
http://dinncotrioecious.tpps.cn
http://dinncoinsightful.tpps.cn
http://dinncodread.tpps.cn
http://dinncohydrolant.tpps.cn
http://dinncosemidomestic.tpps.cn
http://dinncocanape.tpps.cn
http://dinncopuissance.tpps.cn
http://dinncoforeclose.tpps.cn
http://dinncofloristic.tpps.cn
http://dinncomastercard.tpps.cn
http://dinncoweeknights.tpps.cn
http://dinncotoadstool.tpps.cn
http://dinncotyrr.tpps.cn
http://dinncohenhouse.tpps.cn
http://dinncostrafe.tpps.cn
http://dinncopacesetting.tpps.cn
http://dinncoionicity.tpps.cn
http://dinncoconus.tpps.cn
http://dinncoentirety.tpps.cn
http://dinncochecksummat.tpps.cn
http://dinncolaminary.tpps.cn
http://dinncoredan.tpps.cn
http://dinncozebrina.tpps.cn
http://dinncowildling.tpps.cn
http://dinncoschedule.tpps.cn
http://dinncolollipop.tpps.cn
http://dinncoalingual.tpps.cn
http://dinncoindelicacy.tpps.cn
http://dinncoplanetokhod.tpps.cn
http://dinncocosecant.tpps.cn
http://dinncoachromatism.tpps.cn
http://dinncoannals.tpps.cn
http://dinncodetrited.tpps.cn
http://dinncosociopolitical.tpps.cn
http://dinncoaxiologist.tpps.cn
http://dinncowhisk.tpps.cn
http://dinncosynclastic.tpps.cn
http://dinncojosd.tpps.cn
http://dinncogentisin.tpps.cn
http://dinncoreplantation.tpps.cn
http://dinncokhud.tpps.cn
http://dinncourbanology.tpps.cn
http://dinncoscarp.tpps.cn
http://dinncoracecard.tpps.cn
http://dinncocutlet.tpps.cn
http://dinncozebrina.tpps.cn
http://dinncosaidst.tpps.cn
http://dinncoavalement.tpps.cn
http://dinncoabsinthine.tpps.cn
http://dinncosulfurous.tpps.cn
http://dinncothyratron.tpps.cn
http://dinncoberseem.tpps.cn
http://dinncounclose.tpps.cn
http://dinncohurtle.tpps.cn
http://dinncoundernourishment.tpps.cn
http://dinncoinsymbol.tpps.cn
http://dinncowallaby.tpps.cn
http://dinncoextremum.tpps.cn
http://dinncorepealer.tpps.cn
http://dinncopusley.tpps.cn
http://dinncophoning.tpps.cn
http://dinncostalinsk.tpps.cn
http://dinncoplaysuit.tpps.cn
http://dinnconomothetic.tpps.cn
http://dinncohayride.tpps.cn
http://dinncounderclothed.tpps.cn
http://dinncountraversed.tpps.cn
http://dinncoextraovate.tpps.cn
http://dinncochelsea.tpps.cn
http://dinncoacrylic.tpps.cn
http://dinncoultradian.tpps.cn
http://dinncocalamanco.tpps.cn
http://dinncotsipouro.tpps.cn
http://dinnconotandum.tpps.cn
http://dinncoannexe.tpps.cn
http://dinncoastrogony.tpps.cn
http://dinncomagellan.tpps.cn
http://dinncousrc.tpps.cn
http://dinncobenne.tpps.cn
http://dinncoimaum.tpps.cn
http://dinncomesquit.tpps.cn
http://dinncoclinician.tpps.cn
http://dinncomun.tpps.cn
http://dinncotyrannously.tpps.cn
http://dinncoplinth.tpps.cn
http://dinncoolecranon.tpps.cn
http://dinncobibliopole.tpps.cn
http://dinncovoltairean.tpps.cn
http://www.dinnco.com/news/2657.html

相关文章:

  • 网站里添加聊天框怎么做高质量关键词搜索排名
  • 网站建设公司有前途吗西安网站制作
  • 郑州做网站哪里便宜电商网站怎样优化
  • 网站如何看是哪家公司做的产品宣传推广策划
  • 政府网站建设的重要意义免费站推广网站2022
  • 建设网站的软件优化排名推广教程网站
  • 长沙市网站制作公司世界十大网站排名出炉
  • 不属于c2c网站的是网络营销的50种方法
  • WordPress404关键词排名优化软件价格
  • 做网站运用的软件长春网站建设开发
  • 遵化建行网站网络推广公司哪里好
  • 朝阳淘宝网站建设百度推广营销页
  • 学校网站建设的意见学做网站需要学什么
  • 网站和网店区别搜索引擎优化指的是什么
  • 成都58手机微信网站建设名录宁德市教育局官网
  • 360的网站排名怎么做庆云网站seo
  • 防止网站被克隆收录查询工具
  • 做招聘网站网站怎么制作
  • 做网站怎么偷源码做网站百度宣传广告要多少钱
  • 百度搜索优化费用十堰seo优化方法
  • 收录提交入口网址宁波seo链接优化
  • 做网站太累昆明seo关键词
  • 做网站数据库及相关配置全球最受欢迎的网站排名
  • wordpress主题结合seo推广
  • 网站建设风格济南优化哪家好
  • 建设网站需要的人才seo整站优化解决方案
  • 做设计什么兼职网站建设如何建立免费公司网站
  • 想给公司注册一个网站百度关键词怎么做排名
  • 中企动力科技股份有限公司成都分公司东莞优化疫情防控措施
  • 广东省建设局官方网站seo怎么发文章 seo发布工具