宏观扩张__read_mostly
:
#define __read_mostly __attribute__((__section__(".data..read_mostly"))
Run Code Online (Sandbox Code Playgroud)
这个来自 cache.h
__init
:
#define __init __section(.init.text) __cold notrace
Run Code Online (Sandbox Code Playgroud)
从 init.h
__exit
:
#define __exit __section(.exit.text) __exitused __cold notrace
Run Code Online (Sandbox Code Playgroud)
在通过网络搜索后,我没有找到任何关于那里发生的事情的好解释.
附加问题:我听说过内核开发中使用的各种"链接器魔术".任何有关这方面的信息都会很精彩.
我对这些宏的一些想法,他们做什么.就像__init
假设初始化后可以删除功能代码一样.__read_mostly
用于指示数据很少被写入,并且由此最小化缓存未命中.但我不知道他们是如何做到的.我的意思是他们是gcc
扩展.因此理论上它们可以通过小型用户区域代码进行演示.
更新1:
我试图__section__
用任意部分名称测试.测试代码:
#include <stdio.h>
#define __read_mostly __attribute__((__section__("MY_DATA")))
struct ro {
char a;
int b;
char * c;
};
struct ro my_ro __read_mostly = {
.a = 'a',
.b = 3,
.c = NULL,
};
int main(int argc, char **argv) { …
Run Code Online (Sandbox Code Playgroud) 我正在开发内核模块,构建时间开始在我的皮肤下.作为副作用,我在构建期间采取了太多的"咖啡"休息时间.
所以我一直在寻找一种方法来构建我的平台所需的东西."Linux内核简介"的第7章和第8章详细介绍了如何手动完成.这是一个很好的阅读:http://www.kroah.com/lkn/
但是虽然我理解这些东西,但仍然需要进行大量调整才能实现这一目标.
2.6.32及更高版本的内核添加了一个新目标make localmodconfig
.它会扫描lsmod
并适当地更改.config.所以我以为我找到了"自动化".但是这个perl脚本也存在一些问题.
该主题描述了这些问题:https://bbs.archlinux.org/viewtopic.php?pid = 845113
还有一个显然适用于其他人的建议解决方案是直接运行脚本而不是使用make的目标.
虽然对我来说,make localmodconfig根本不起作用.它的原因如下:
make clean
make mrproper
cp /boo/config-'uname -r' .config
make localmodconfig
Run Code Online (Sandbox Code Playgroud)
它停止了
vboxguest config not found!!
nf_defrag_ipv6 config not found!!
vboxsf config not found!!
vboxvideo config not found!!
Run Code Online (Sandbox Code Playgroud)
事情是我的内核开发环境是在virtualbox里面.当我选择安装"virtualbox guest addtion"时安装了这些vbox模块.
netfilter模块可能是一个特定于分发的模块(很多netfilter模块不是主线内核的一部分,所以它对我来说不是一个冲击),它不包含在主线内核中.
现在解决方法显然卸载了这些模块并再次尝试.但我在想是否有补丁streamline_config.pl
可以让用户在他/她想要时排除某些模块.问题是我零有关Perl的知识,我喜欢这样.
所以我的问题简而言之
修补,streamline_config.pl
所以我可以给出一个模块名称列表作为参数,它将从处理配置文件中排除.
该脚本位于kernel.org
编辑:删除了有关perl脚本未运行的内容.正如mugen kenichi指出的那样(我多么愚蠢?).但localmodconfig
由于源树下没有一些模块代码,仍然无法工作.修补streamline_config.pl
仍然有效的要求.
我正在尝试从烧瓶应用程序运行shell命令并尝试获取输出.我正在尝试的应用程序如下:
from flask import Flask
import subprocess
app = Flask(__name__)
@app.route("/")
def hello():
cmd = ["ls"," -l"]
p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
out,err = p.communicate()
return out
if __name__ == "__main__" :
app.run()
Run Code Online (Sandbox Code Playgroud)
shell命令没问题.我在外面检查过,但是从浏览器中我得到"内部严重错误".
编辑:由于第一个答案指出它有一个错字...但现在它运行正常但我没有在我的浏览器中获得任何输出...
我-lrt
将最后一个链接器标志作为编译器.但仍然得到这个错误.
arif@khost:~/sak/sak.exosip$ gcc eXo_init.c -I/opt/osip2/include -I/opt/exosip/include -L/opt/osip2/lib -L/opt/exosip/lib -leXosip2 -losipparser2 -losip2 -lrt
/opt/osip2/lib/libosip2.so: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
手册页说:
NAME
clock_getres, clock_gettime, clock_settime - clock and time functions
SYNOPSIS
#include <time.h>
int clock_getres(clockid_t clk_id, struct timespec *res);
int clock_gettime(clockid_t clk_id, struct timespec *tp);
int clock_settime(clockid_t clk_id, const struct timespec *tp);
Link with -lrt.
Run Code Online (Sandbox Code Playgroud)
所以我有点困惑,我做错了.
我试图在librt.so
没有运气的情况下阅读符号:
arif@khost:~/sak/ortp/src/tests$ nm /lib/x86_64-linux-gnu/librt-2.15.so
nm: /lib/x86_64-linux-gnu/librt-2.15.so: no symbols
Run Code Online (Sandbox Code Playgroud)
更新1我无法读取符号的原因librt.so
是它们被"剥离".我在哪里可以获得符号名称?
arif@khost:~/sak/ortp/src/tests$ file /lib/x86_64-linux-gnu/librt-2.15.so
/lib/x86_64-linux-gnu/librt-2.15.so: ELF …
Run Code Online (Sandbox Code Playgroud) 好吧,我的烧瓶应用程序中有这个:
@app.route("/changeip/<ip>")
def change_ip(ip) :
return ip
Run Code Online (Sandbox Code Playgroud)
现在如果我调用它:
http://127.0.0.1:5000/changeip?ip=1.2.2.2
Run Code Online (Sandbox Code Playgroud)
它吐出"未找到网址"......我在这里做错了什么?
我正在尝试从源代码构建gperf(Google的探查器)。在构建过程中,出现以下错误:
src/stacktrace_config.h:58:5: error: #error Cannnot calculate stack trace: need either libunwind or frame-pointers (see INSTALL file)
src/stacktrace.cc:109:3: error: #error Cannot calculate stack trace: will need to write for your environment
make: *** [stacktrace.lo] Error 1
Run Code Online (Sandbox Code Playgroud)
所以看来我需要libunwind
。
1)我从萨凡纳(Savannah)的git repo中获得了图书馆。2)安装在中/opt/unwind
。3)我还添加/opt/unwind/lib/pkgconfig
了我的PKG_CONFIG_PATH
。4)我进行了编辑,libunwind.pc
以使两者pkg-config --cflags --libs libunwind
都具有正确的值。5)本人添加了libunwind.conf
在/etc/ld.so.conf.d/
指向/opt/unwind/lib
。
所有这些之后,我已经./configure
在gperf
根目录中重新运行。
在config.log
读取以下内容:
configure:15852: checking libunwind.h usability
configure:15852: gcc -c -g -O2 conftest.c >&5
conftest.c:67:23: fatal …
Run Code Online (Sandbox Code Playgroud) 它是一个生成随机厄米特矩阵厄米特矩阵的小代码.
我在每次调用rand()之前调用了srand().但输出中仍然没有随机性.
我使用c99的复杂数据类型功能来创建一个埃尔米特矩阵.我不确定我错在哪里:(
#include <stdio.h>
#include <math.h>
#include <complex.h>
#include <stdlib.h>
#include <time.h>
#define MATSIZE 5
#define RAND_RANGE 100
double complex mat[MATSIZE][MATSIZE];
void gen_mat()
{
int i =0,j;
int real;
int img;
for( ;i < MATSIZE; i++)
{
srand(time(NULL));
real = rand()%RAND_RANGE + 1;
srand(time(NULL));
img = rand()%RAND_RANGE + 1;
for(j = MATSIZE; j != i ; j--)
{
mat[i][j] = real + img * I;
mat[j][i] = conj(mat[i][j]);
}
srand(time(NULL));
if(i == j)
mat[i][i] = rand()%RAND_RANGE + …
Run Code Online (Sandbox Code Playgroud)