MACHINE_START分析

本文详细解析了mini2440开发板在Linux2.6.32.2内核中的启动配置过程,重点介绍了MACHINE_START宏的定义及展开,并解释了各成员函数在内核不同阶段的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MACHINE_START分析

在友善mini2440提供的linux2.6.32.2内核中,有如下定义:
MACHINE_START(MINI2440, "FriendlyARM Mini2440 development board")
.phys_io = S3C2410_PA_UART,
.io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
.boot_params = S3C2410_SDRAM_PA + 0x100,


.init_irq = s3c24xx_init_irq,
.map_io = mini2440_map_io,
.init_machine = mini2440_machine_init,
.timer = &s3c24xx_timer,
MACHINE_END


下面分析一下:
在include/asm-arm/mach/arch.h中,有定义
#define MACHINE_START(_type,_name) \
static const struct machine_desc __mach_desc_##_type \
 __used \
 __attribute__((__section__(".arch.info.init"))) = { \
.nr = MACH_TYPE_##_type, \
.name = _name,


#define MACHINE_END \
};


列出machine_desc的定义:
struct machine_desc {
unsigned int nr;
unsigned int phys_io;
unsigned int io_pg_offst;


const char *name;
unsigned long boot_params;


unsigned int video_start;
unsigned int video_end;


unsigned int reserve_lp0 :1;
unsigned int reserve_lp1 :1;
unsigned int reserve_lp2 :1;
unsigned int soft_reboot :1;
void (*fixup)(struct machine_desc *,
struct tag *, char **,
struct meminfo *);
void (*map_io)(void);
void (*init_irq)(void);
struct sys_timer *timer;
void (*init_machine)(void);
};




按定义展开后:
static const struct machine_desc __mach_desc_MINI2440 \
 __used \
 __attribute__((__section__(".arch.info.init"))) = {
.nr = MACH_TYPE_MINI2440,
.name = "FriendlyARM Mini2440 development board",
.phys_io = S3C2410_PA_UART,
.io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
.boot_params = S3C2410_SDRAM_PA + 0x100,
.init_irq = s3c24xx_init_irq,
.map_io = mini2440_map_io,
.init_machine = mini2440_machine_init,
.timer = &s3c24xx_timer,
};
MACH_TYPE_MINI2440 是mini2440开发板在linux中的机器号。
"FriendlyARM Mini2440 development board"是开发板信息,在终端输入cat /proc/cpuinfo可以查看。


MACHINE_START主要是定义了"struct machine_desc"的类型,放在 section(".arch.info.init"),是初始化数据,Kernel 起来之后将被丢弃。
其余各个成员函数在setup_arch()中被赋值到内核结构体,在不同时期被调用:
1. .init_machine 在 arch/arm/kernel/setup.c 中被 customize_machine 调用,放在 arch_initcall() 段里面,会自动按顺序被调用。
2. .init_irq在start_kernel() --> init_IRQ() --> init_arch_irq()中被调用
3. .map_io 在 setup_arch() --> paging_init() --> devicemaps_init()中被调用
4. .timer是定义系统时钟,定义TIMER4为系统时钟,在arch/arm/plat-s3c/time.c中体现。在start_kernel() --> time_init()中被调用。
5. .boot_params是bootloader向内核传递的参数的位置,这要和bootloader中参数的定义要一致。


其他主要都在 setup_arch() 中用到。

请你分析这段代码:import pandas as pd # 读取Excel文件,构建工序字典(工序名称: {机器: 加工时间}) file_path = r'F:\学校文件\论文\草稿\mk01.xlsx' df = pd.read_excel(file_path, sheet_name='Sheet1') process_dict = {} for idx, row in df.iterrows(): job = row['MK01'] op = row['gx'] machines = {} for col in df.columns[2:]: # 从M1到M6 time = row[col] if pd.notna(time): machines[col] = time process_dict[op] = machines # 假设这里的工序编码和机器编码是编码程序的输出 operation_sequence = [10, 5, 3, 10, 3, 10, 3, 1, 6, 10, 5, 6, 6, 9, 4, 2, 8, 7, 1, 7, 5, 9, 10, 1, 9, 5, 10, 8, 3, 1, 6, 3, 6, 8, 2, 6, 7, 2, 9, 4, 7, 1, 5, 9, 4, 4, 5, 8, 4, 7, 1, 8, 2, 9, 2] # 示例工序编码 machine_code = [6, 2, 2, 3, 6, 5, 1, 1, 6, 6, 1, 1, 3, 6, 1, 2, 6, 6, 5, 4, 2, 1, 4, 3, 4, 1, 4, 3, 6, 1, 2, 5, 1, 1, 3, 4, 3, 1, 1, 2, 5, 3, 4, 6, 3, 5, 3, 2, 6, 3, 4, 4, 4, 4, 1] # 示例机器编码 # 初始化变量 jobs = df['MK01'].unique() job_numbers = {job: int(job[3:]) for job in jobs} job_operations = {job: len(df[df['MK01'] == job]) for job in jobs} machine_start_times = [0] * 6 # 每台机器的当前可用时间 job_current_op = {job: 0 for job in jobs} total_time = 0 machine_loads = [0] * 6 # 初始化每台机器的负载 # 解码过程 for i in range(len(operation_sequence)): job_char = operation_sequence[i] job = f'job{job_char}' op_index = job_current_op[job] op_name = f'O{job_char}{op_index + 1}' job_current_op[job] += 1 machine_index = machine_code[i] - 1 # 机器编号从1开始,转换为索引 machine = f'M{machine_index + 1}' # 检查该工序是否支持在所选机器上加工 if machine in process_dict[op_name]: # 获取该工序在所选机器上的加工时间 processing_time = process_dict[op_name][machine] # 确定该工序的开始时间,取决于机器的可用时间和工件上一工序的完成时间 job_last_finish_time = max( [machine_start_times[j] for j in range(6) if op_name in process_dict and machine in process_dict[op_name]]) start_time = max(machine_start_times[machine_index], job_last_finish_time) # 更新机器的可用时间 machine_start_times[machine_index] = start_time + processing_time # 更新总加工时间 total_time = max(total_time, machine_start_times[machine_index]) # 更新机器的负载 machine_loads[machine_index] += processing_time print( f"工件 {job} 的工序 {op_name} 在机器 {machine} 上,从时间 {start_time} 开始加工,加工时间为 {processing_time}") else: print(f"错误:工序 {op_name} 不支持在机器 {machine} 上加工。") print(f"总加工时间: {total_time}") # 输出每台机器的负载 for i in range(6): print(f"机器 M{i + 1} 的负载: {machine_loads[i]}")
最新发布
03-23
New_Lot_Loop_Info=\ {'C101': {390: {'PSR01': 40, 'PSR03': 35}, 410: {'HCI09': 20, 'HCI0B': 20}, 420: {'SEM04': 6, 'SEM05': 6, 'SEM06': 6, 'SEM07': 6, 'SEM67': 6}, 465: {'WPES07': 12, 'WPES65': 12}, 448: {'OCD02': 8, 'OCD03': 8}, 452: {'WPES04': 12, 'WPES08': 12}, 453: {'EPI07': 110, 'EPI08': 110, 'EPI0k': 130}}, 'C102': {390: {'PSR01': 40, 'PSR03': 35}, 410: {'HCI09': 20, 'HCI0B': 20}, 420: {'SEM04': 6, 'SEM05': 6, 'SEM06': 6, 'SEM07': 6, 'SEM67': 6}, 465: {'WPES07': 12, 'WPES65': 12}, 448: {'OCD02': 8, 'OCD03': 8}, 452: {'WPES04': 12, 'WPES08': 12}, 453: {'EPI07': 110, 'EPI08': 110, 'EPI0k': 130}}, 'C103': {390: {'PSR01': 40, 'PSR03': 35}, 410: {'HCI09': 20, 'HCI0B': 20}, 420: {'SEM04': 6, 'SEM05': 6, 'SEM06': 6, 'SEM07': 6, 'SEM67': 6}, 465: {'WPES07': 12, 'WPES65': 12}, 448: {'OCD02': 8, 'OCD03': 8}, 452: {'WPES04': 12, 'WPES08': 12}, 453: {'EPI07': 110, 'EPI08': 110, 'EPI0k': 130}}} # 定义变量 x={} # Lot是否在某个step_id的某个机台上加工 Step_Time_S={} # Lot在某个step_id的开始时间 Step_Time_E={} # Lot在某个step_id的结束时间 all_tasks={} Machine_Task = collections.defaultdict(list) task_type = collections.namedtuple("task_type", "start end") for lot_id,step_info in New_Lot_Loop_Info.items(): for step_id,machine_info in step_info.items(): Step_Time_S[lot_id,step_id]=model.NewIntVar(0,MAX_TIME,f"{lot_id}_{step_id}_start_time") Step_Time_E[lot_id,step_id]=model.NewIntVar(0,MAX_TIME,f"{lot_id}_{step_id}_end_time") for machine_id, process_time in machine_info.items(): x[lot_id,step_id,machine_id]=model.NewBoolVar(f"x_{lot_id}_{step_id}_{machine_id}") Process_Time = model.NewIntVar(0, MAX_TIME, f"Real_Process_Time_{lot_id}_{step_id}_{machine_id}") model.Add(Process_Time == process_time).OnlyEnforceIf(x[lot_id, step_id,machine_id]) Machine_Time_S = model.NewIntVar(0, MAX_TIME, f"Machine_Time_S_{lot_id}_{step_id}_{machine_id}") Machine_Time_E = model.NewIntVar(0, MAX_TIME, f"Machine_Time_E_{lot_id}_{step_id}_{machine_id}") model.Add(Machine_Time_S == 0).OnlyEnforceIf(x[lot_id,step_id,machine_id].Not()) model.Add(Machine_Time_E == 0).OnlyEnforceIf(x[lot_id,step_id,machine_id].Not()) Pro_Task = model.NewIntervalVar(start=Machine_Time_S, size= Process_Time, end=Machine_Time_E, name=f"Pro_Task_{lot_id}_{step_id}_{machine_id}") Machine_Task[machine_id].append(Pro_Task) # 将加工任务写入 all_tasks[lot_id, step_id, machine_id] = task_type(start=Machine_Time_S, end=Machine_Time_E) # 约束1:每个lot在每个step_id只能在一台机台上被加工 for lot_id,step_list in New_Lot_Loop_Info.items(): for step_id, machine_info in step_list.items(): model.Add(sum(x[lot_id,step_id,machine_id] for machine_id in machine_info) == 1) # 约束2:将每个step_id的开始时间和结束时间与上了哪个机器有关 for lot_id,step_info in New_Lot_Loop_Info.items(): for step_id,machine_info in step_info.items(): model.AddMaxEquality(Step_Time_S[lot_id, step_id],[all_tasks[lot_id, step_id, machine_id].start for machine_id in machine_info]) model.AddMaxEquality(Step_Time_E[lot_id, step_id],[all_tasks[lot_id, step_id, machine_id].end for machine_id in machine_info]) # 计算每个EPI机台的最晚结束时间 EPI_Machine_EndTime = {} # 存储每个EPI机台的最后一个任务结束时间 for machine_id in Machine_Task: if machine_id.startswith("EPI"): # 筛选EPI类型机台 max_end = model.NewIntVar(0, MAX_TIME, f"max_end_{machine_id}") end_times = [task.end for task in Machine_Task[machine_id]] model.AddMaxEquality(max_end, end_times) EPI_Machine_EndTime[machine_id] = max_end代码报错:AttributeError: 'IntervalVar' object has no attribute 'end'
03-14
# 使用约束编程求解器 model=cp_model.CpModel() MAX_TIME=10000 x={} # Lot是否在某个step_id的某个机台上加工 Step_Time_S={} # Lot在某个step_id的开始时间 Step_Time_E={} # Lot在某个step_id的结束时间 all_tasks={} Machine_Task = collections.defaultdict(list) EPI_Task = collections.defaultdict(list) # 专门记录EPI机台的加工任务 task_type = collections.namedtuple("task_type", "start end") for lot_id,step_info in New_Lot_Loop_Info.items(): for step_id,machine_info in step_info.items(): Step_Time_S[lot_id,step_id]=model.NewIntVar(0,MAX_TIME,f"{lot_id}_{step_id}_start_time") Step_Time_E[lot_id,step_id]=model.NewIntVar(0,MAX_TIME,f"{lot_id}_{step_id}_end_time") for machine_id, process_time in machine_info.items(): x[lot_id,step_id,machine_id]=model.NewBoolVar(f"x_{lot_id}_{step_id}_{machine_id}") Process_Time = model.NewIntVar(0, MAX_TIME, f"Real_Process_Time_{lot_id}_{step_id}_{machine_id}") model.Add(Process_Time == process_time).OnlyEnforceIf(x[lot_id, step_id,machine_id]) Machine_Time_S = model.NewIntVar(0, MAX_TIME, f"Machine_Time_S_{lot_id}_{step_id}_{machine_id}") Machine_Time_E = model.NewIntVar(0, MAX_TIME, f"Machine_Time_E_{lot_id}_{step_id}_{machine_id}") model.Add(Machine_Time_S == 0).OnlyEnforceIf(x[lot_id,step_id,machine_id].Not()) model.Add(Machine_Time_E == 0).OnlyEnforceIf(x[lot_id,step_id,machine_id].Not()) Pro_Task2 = model.NewIntervalVar(start=Machine_Time_S, size=Process_Time, end=Machine_Time_E,name=f"Pro_Task_{lot_id}_{step_id}_{machine_id}") EPI_Task[machine_id].append(Pro_Task2) all_tasks[lot_id, step_id, machine_id] = task_type(start=Machine_Time_S, end=Machine_Time_E) for lot_id,step_list in New_Lot_Loop_Info.items(): for step_id, machine_info in step_list.items(): model.Add(sum(x[lot_id,step_id,machine_id] for machine_id in machine_info) == 1) for lot_id,step_info in New_Lot_Loop_Info.items(): for step_id,machine_info in step_info.items(): model.AddMaxEquality(Step_Time_S[lot_id, step_id],[all_tasks[lot_id, step_id, machine_id].start for machine_id in machine_info]) model.AddMaxEquality(Step_Time_E[lot_id, step_id],[all_tasks[lot_id, step_id, machine_id].end for machine_id in machine_info]) """进入EPI的约束""" EPI_Machine=['EPI07','EPI08','EPI0k'] Order=20 # 每个EPI机台最多有20个加工任务 z = {} # Lot在EPI的第m机台的第order位次执行加工任务 or_used={} # 机台的第几个位次存在被加工的lot Order_time_S={} Order_time_E={} for lot_id,step_info in New_Lot_Loop_Info.items(): for step_id,machine_info in step_info.items(): if step_id==453: for m in EPI_Machine: for order in range(Order): z[lot_id, m, order] = model.NewBoolVar(f"x_{lot_id}_{m}_{order}") for m in EPI_Machine: for order in range(Order): or_used[m, order] = model.NewBoolVar(f"or_used_{m}_{order}") Order_time_S[m, order] = model.NewIntVar(0, 10000, f'Order_time_S_{m}_{order}') Order_time_E[m, order] = model.NewIntVar(0, 10000, f'Order_time_E_{m}_{order}') for m in EPI_Machine: for order in range(Order-1): model.Add(or_used[m, order] >= or_used[m, order+1]) for lot_id,step_info in New_Lot_Loop_Info.items(): model.Add(sum(z[lot_id,m,order] for order in range(Order) for m in EPI_Machine) == 1) for machine in EPI_Task: model.AddCumulative(EPI_Task[machine], [1 for _ in EPI_Task[machine]], 2) 修改代码,在上述模型中增加约束条件,如果两个Lot因为AddCumulative进行了重叠,那重叠的时间区间不能大于50
03-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值