void sysfs_notify(struct kobject * k, char *dir, char *attr) { struct dentry *de = k->dentry; if (de) dget(de); if (de && dir) de = step_down(de, dir); if (de && attr) de = step_down(de, attr); if (de) { struct sysfs_dirent * sd = de->d_fsdata; if (sd) atomic_inc(&sd->s_event); wake_up_interruptible(&k->poll); dput(de); } }
int movegen(struct Game* game, int move_count) { U64 temp_move, temp_move2, temp_piece; U32 from, to, move; U64 free_squares = game->board[OCCUPIED][0]; if (game->to_move == WHITE) { /***************/ /* WHITE PAWNS */ /***************/ temp_move = step_up(game->board[PAWNS][WHITE]) & free_squares; temp_move2 = temp_move; /* single pushes */ while (temp_move) { to = bit_scan_forward(temp_move); if (to/8 == 7) { /* time for a promotion */ game->move_buffer[move_count++] = create_move(to-8,to,BISHOP_PROMO_FLAG); game->move_buffer[move_count++] = create_move(to-8,to,KNIGHT_PROMO_FLAG); game->move_buffer[move_count++] = create_move(to-8,to,ROOK_PROMO_FLAG); game->move_buffer[move_count++] = create_move(to-8,to,QUEEN_PROMO_FLAG); } else game->move_buffer[move_count++] = create_move(to-8,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* double pushes */ temp_move2 = step_up(temp_move2) & free_squares & rank4; while (temp_move2) { to = bit_scan_forward(temp_move2); game->move_buffer[move_count++] = create_move(to-16,to,DOUBLE_PAWN_PUSH_FLAG); temp_move2 &= temp_move2 - 1; } /* captures */ /* TODO: add en passante capture */ temp_piece = game->board[PAWNS][WHITE]; while (temp_piece) { from = bit_scan_forward(temp_piece); temp_move = pawn_attacks[WHITE][from] & game->board[PIECES][BLACK]; while (temp_move) { to = bit_scan_forward(temp_move); if (to/8 == 7) { /* time for a promotion */ game->move_buffer[move_count++] = create_move(from,to,BISHOP_PROMO_CAPTURE_FLAG); game->move_buffer[move_count++] = create_move(from,to,KNIGHT_PROMO_CAPTURE_FLAG); game->move_buffer[move_count++] = create_move(from,to,ROOK_PROMO_CAPTURE_FLAG); game->move_buffer[move_count++] = create_move(from,to,QUEEN_PROMO_CAPTURE_FLAG); } else game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } temp_piece &= temp_piece - 1; } /*****************/ /* WHITE KNIGHTS */ /*****************/ temp_piece = game->board[KNIGHTS][WHITE]; while (temp_piece) { from = bit_scan_forward(temp_piece); /* quiets */ temp_move = knight_table[from] & free_squares; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* captures */ temp_move = knight_table[from] & game->board[PIECES][BLACK]; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } temp_piece &= temp_piece - 1; } /*****************/ /* WHITE BISHOPS */ /*****************/ temp_piece = game->board[BISHOPS][WHITE]; while (temp_piece) { from = bit_scan_forward(temp_piece); temp_move2 = get_bishop_attacks(game->board[OCCUPIED][1], from); /* quiets */ temp_move = temp_move2 & free_squares; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* captures */ temp_move = temp_move2 & game->board[PIECES][BLACK]; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } temp_piece &= temp_piece - 1; } /***************/ /* WHITE ROOKS */ /***************/ temp_piece = game->board[ROOKS][WHITE]; while (temp_piece) { from = bit_scan_forward(temp_piece); temp_move2 = get_rook_attacks(game->board[OCCUPIED][1], from); /* quiets */ temp_move = temp_move2 & free_squares; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* captures */ temp_move = temp_move2 & game->board[PIECES][BLACK]; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } temp_piece &= temp_piece - 1; } /****************/ /* WHITE QUEENS */ /****************/ temp_piece = game->board[QUEENS][WHITE]; while (temp_piece) { from = bit_scan_forward(temp_piece); temp_move2 = get_queen_attacks(game->board[OCCUPIED][1], from); /* quiets */ temp_move = temp_move2 & free_squares; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* captures */ temp_move = temp_move2 & game->board[PIECES][BLACK]; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } temp_piece &= temp_piece - 1; } /**************/ /* WHITE KINGS */ /**************/ temp_piece = game->board[KINGS][WHITE]; from = bit_scan_forward(temp_piece); /* quiets */ temp_move = king_table[from] & free_squares; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* captures */ temp_move = king_table[from] & game->board[PIECES][BLACK]; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } /* TODO: add castling moves here after writing is_attacked function */ } else { /* to_move == BLACK */ /***************/ /* BLACK PAWNS */ /***************/ temp_move = step_down(game->board[PAWNS][BLACK]) & free_squares; temp_move2 = temp_move; /* single pushes */ while (temp_move) { to = bit_scan_forward(temp_move); if (to/8 == 0) { /* time for a promotion */ game->move_buffer[move_count++] = create_move(to+8,to,BISHOP_PROMO_FLAG); game->move_buffer[move_count++] = create_move(to+8,to,KNIGHT_PROMO_FLAG); game->move_buffer[move_count++] = create_move(to+8,to,ROOK_PROMO_FLAG); game->move_buffer[move_count++] = create_move(to+8,to,QUEEN_PROMO_FLAG); } else game->move_buffer[move_count++] = create_move(to+8,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* double pushes */ temp_move2 = step_down(temp_move2) & free_squares & rank5; while (temp_move2) { to = bit_scan_forward(temp_move2); game->move_buffer[move_count++] = create_move(to+16,to,DOUBLE_PAWN_PUSH_FLAG); temp_move2 &= temp_move2 - 1; } /* captures */ /* TODO: add en passante capture */ temp_piece = game->board[PAWNS][BLACK]; while (temp_piece) { from = bit_scan_forward(temp_piece); temp_move = pawn_attacks[BLACK][from] & game->board[PIECES][WHITE]; while (temp_move) { to = bit_scan_forward(temp_move); if (to/8 == 7) { /* time for a promotion */ game->move_buffer[move_count++] = create_move(from,to,BISHOP_PROMO_CAPTURE_FLAG); game->move_buffer[move_count++] = create_move(from,to,KNIGHT_PROMO_CAPTURE_FLAG); game->move_buffer[move_count++] = create_move(from,to,ROOK_PROMO_CAPTURE_FLAG); game->move_buffer[move_count++] = create_move(from,to,QUEEN_PROMO_CAPTURE_FLAG); } else game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } temp_piece &= temp_piece - 1; } /*****************/ /* BLACK KNIGHTS */ /*****************/ temp_piece = game->board[KNIGHTS][BLACK]; while (temp_piece) { from = bit_scan_forward(temp_piece); /* quiets */ temp_move = knight_table[from] & free_squares; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* captures */ temp_move = knight_table[from] & game->board[PIECES][WHITE]; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } temp_piece &= temp_piece - 1; } /*****************/ /* BLACK BISHOPS */ /*****************/ temp_piece = game->board[BISHOPS][BLACK]; while (temp_piece) { from = bit_scan_forward(temp_piece); temp_move2 = get_bishop_attacks(game->board[OCCUPIED][1], from); /* quiets */ temp_move = temp_move2 & free_squares; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* captures */ temp_move = temp_move2 & game->board[PIECES][WHITE]; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } temp_piece &= temp_piece - 1; } /***************/ /* BLACK ROOKS */ /***************/ temp_piece = game->board[ROOKS][BLACK]; while (temp_piece) { from = bit_scan_forward(temp_piece); temp_move2 = get_rook_attacks(game->board[OCCUPIED][1], from); /* quiets */ temp_move = temp_move2 & free_squares; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* captures */ temp_move = temp_move2 & game->board[PIECES][WHITE]; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } temp_piece &= temp_piece - 1; } /****************/ /* BLACK QUEENS */ /****************/ temp_piece = game->board[QUEENS][BLACK]; while (temp_piece) { from = bit_scan_forward(temp_piece); temp_move2 = get_queen_attacks(game->board[OCCUPIED][1], from); /* quiets */ temp_move = temp_move2 & free_squares; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* captures */ temp_move = temp_move2 & game->board[PIECES][WHITE]; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } temp_piece &= temp_piece - 1; } /**************/ /* BLACK KINGS */ /**************/ temp_piece = game->board[KINGS][BLACK]; from = bit_scan_forward(temp_piece); /* quiets */ temp_move = king_table[from] & free_squares; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,QUIET_FLAG); temp_move &= temp_move - 1; } /* captures */ temp_move = king_table[from] & game->board[PIECES][WHITE]; while (temp_move) { to = bit_scan_forward(temp_move); game->move_buffer[move_count++] = create_move(from,to,CAPTURE_FLAG); temp_move &= temp_move - 1; } } return move_count; }
static void exynos5250_monitor(struct busfreq_data *data, struct opp **mif_opp, struct opp **int_opp) { int i; unsigned int cpu_load_average = 0; unsigned int ddr_c_load_average = 0; unsigned int ddr_l_load_average = 0; unsigned int ddr_r1_load_average = 0; unsigned int right0_load_average = 0; unsigned int ddr_load_average; unsigned long cpufreq = 0; unsigned long freq_int_right0 = 0; unsigned long lockfreq[PPMU_TYPE_END]; unsigned long freq[PPMU_TYPE_END]; unsigned long cpu_load; unsigned long ddr_load=0; unsigned long ddr_load_int=0; unsigned long ddr_c_load; unsigned long ddr_r1_load; unsigned long ddr_l_load; unsigned long right0_load; struct opp *opp[PPMU_TYPE_END]; unsigned long newfreq[PPMU_TYPE_END]; ppmu_update(data->dev[PPMU_MIF], 3); /* Convert from base xxx to base maxfreq */ cpu_load = div64_u64(ppmu_load[PPMU_CPU] * data->curr_freq[PPMU_MIF], data->max_freq[PPMU_MIF]); ddr_c_load = div64_u64(ppmu_load[PPMU_DDR_C] * data->curr_freq[PPMU_MIF], data->max_freq[PPMU_MIF]); ddr_r1_load = div64_u64(ppmu_load[PPMU_DDR_R1] * data->curr_freq[PPMU_MIF], data->max_freq[PPMU_MIF]); ddr_l_load = div64_u64(ppmu_load[PPMU_DDR_L] * data->curr_freq[PPMU_MIF], data->max_freq[PPMU_MIF]); right0_load = div64_u64(ppmu_load[PPMU_RIGHT0_BUS] * data->curr_freq[PPMU_INT], data->max_freq[PPMU_INT]); data->load_history[PPMU_CPU][data->index] = cpu_load; data->load_history[PPMU_DDR_C][data->index] = ddr_c_load; data->load_history[PPMU_DDR_R1][data->index] = ddr_r1_load; data->load_history[PPMU_DDR_L][data->index] = ddr_l_load; data->load_history[PPMU_RIGHT0_BUS][data->index++] = right0_load; if (data->index >= LOAD_HISTORY_SIZE) data->index = 0; for (i = 0; i < LOAD_HISTORY_SIZE; i++) { cpu_load_average += data->load_history[PPMU_CPU][i]; ddr_c_load_average += data->load_history[PPMU_DDR_C][i]; ddr_r1_load_average += data->load_history[PPMU_DDR_R1][i]; ddr_l_load_average += data->load_history[PPMU_DDR_L][i]; right0_load_average += data->load_history[PPMU_RIGHT0_BUS][i]; } /* Calculate average Load */ cpu_load_average /= LOAD_HISTORY_SIZE; ddr_c_load_average /= LOAD_HISTORY_SIZE; ddr_r1_load_average /= LOAD_HISTORY_SIZE; ddr_l_load_average /= LOAD_HISTORY_SIZE; right0_load_average /= LOAD_HISTORY_SIZE; if (ddr_c_load >= ddr_l_load) { ddr_load = ddr_c_load; ddr_load_average = ddr_c_load_average; } else { ddr_load = ddr_l_load; ddr_load_average = ddr_l_load_average; } ddr_load_int = ddr_load; //Calculate MIF/INT frequency level if (ddr_r1_load >= MIF_R1_THRESHOLD) { freq[PPMU_MIF] = data->max_freq[PPMU_MIF]; if (right0_load >= INT_RIGHT0_THRESHOLD) { freq[PPMU_INT] = data->max_freq[PPMU_INT]; goto go_max; } else { freq_int_right0 = div64_u64(data->max_freq[PPMU_INT] * right0_load, INT_RIGHT0_THRESHOLD); } } else { // Caculate next MIF frequency if (ddr_load >= MIF_MAX_THRESHOLD) { freq[PPMU_MIF] = data->max_freq[PPMU_MIF]; } else if ( ddr_load < IDLE_THRESHOLD) { if (ddr_load_average < IDLE_THRESHOLD) freq[PPMU_MIF] = step_down(data, PPMU_MIF, 1); else freq[PPMU_MIF] = data->curr_freq[PPMU_MIF]; } else { if (ddr_load < ddr_load_average) { ddr_load = ddr_load_average; if (ddr_load >= MIF_MAX_THRESHOLD) ddr_load = MIF_MAX_THRESHOLD; } freq[PPMU_MIF] = div64_u64(data->max_freq[PPMU_MIF] * ddr_load, MIF_MAX_THRESHOLD); } freq_int_right0 = div64_u64(data->max_freq[PPMU_INT] * right0_load, INT_RIGHT0_THRESHOLD); } // Caculate next INT frequency if (ddr_load_int >= INT_MAX_THRESHOLD) { freq[PPMU_INT] = data->max_freq[PPMU_INT]; } else if ( ddr_load_int < IDLE_THRESHOLD) { if (ddr_load_average < IDLE_THRESHOLD) freq[PPMU_INT] = step_down(data, PPMU_INT, 1); else freq[PPMU_INT] = data->curr_freq[PPMU_INT]; } else { if (ddr_load_int < ddr_load_average) { ddr_load_int = ddr_load_average; if (ddr_load_int >= INT_MAX_THRESHOLD) ddr_load_int = INT_MAX_THRESHOLD; } freq[PPMU_INT] = div64_u64(data->max_freq[PPMU_INT] * ddr_load_int, INT_MAX_THRESHOLD); } freq[PPMU_INT] = max(freq[PPMU_INT], freq_int_right0); if (freq[PPMU_INT] == data->max_freq[PPMU_INT]) freq[PPMU_MIF] = data->max_freq[PPMU_MIF]; go_max: #ifdef BUSFREQ_PROFILE_DEBUG printk(KERN_DEBUG "cpu[%ld] l[%ld] c[%ld] r1[%ld] rt[%ld] m_load[%ld] i_load[%ld]\n", cpu_load, ddr_l_load, ddr_c_load, ddr_r1_load, right0_load, ddr_load, ddr_load_int); #endif lockfreq[PPMU_MIF] = (dev_max_freq(data->dev[PPMU_MIF])/1000)*1000; lockfreq[PPMU_INT] = (dev_max_freq(data->dev[PPMU_MIF])%1000)*1000; #ifdef BUSFREQ_PROFILE_DEBUG printk(KERN_DEBUG "i_cf[%ld] m_cf[%ld] i_nf[%ld] m_nf[%ld] lock_Mfreq[%ld] lock_Ifreq[%ld]\n", data->curr_freq[PPMU_INT],data->curr_freq[PPMU_MIF],freq[PPMU_INT], freq[PPMU_MIF], lockfreq[PPMU_MIF], lockfreq[PPMU_INT]); #endif newfreq[PPMU_MIF] = max(lockfreq[PPMU_MIF], freq[PPMU_MIF]); newfreq[PPMU_INT] = max(lockfreq[PPMU_INT], freq[PPMU_INT]); opp[PPMU_MIF] = opp_find_freq_ceil(data->dev[PPMU_MIF], &newfreq[PPMU_MIF]); opp[PPMU_INT] = opp_find_freq_ceil(data->dev[PPMU_INT], &newfreq[PPMU_INT]); *mif_opp = opp[PPMU_MIF]; *int_opp = opp[PPMU_INT]; }
static void exynos5250_monitor(struct busfreq_data *data, struct opp **mif_opp, struct opp **int_opp) { int i; unsigned int cpu_load_average = 0; unsigned int dmc_c_load_average = 0; unsigned int dmc_l_load_average = 0; unsigned int dmc_r1_load_average = 0; unsigned int dmc_load_average; unsigned long cpufreq = 0; unsigned long lockfreq; unsigned long dmcfreq; unsigned long cpu_load; unsigned long dmc_load; unsigned long dmc_c_load; unsigned long dmc_r1_load; unsigned long dmc_l_load; struct opp *opp[PPMU_TYPE_END]; unsigned long newfreq[PPMU_TYPE_END]; ppmu_update(data->dev[PPMU_MIF], 3); /* Convert from base xxx to base maxfreq */ cpu_load = div64_u64(ppmu_load[PPMU_CPU] * data->curr_freq[PPMU_MIF], data->max_freq[PPMU_MIF]); dmc_c_load = div64_u64(ppmu_load[PPMU_DDR_C] * data->curr_freq[PPMU_MIF], data->max_freq[PPMU_MIF]); dmc_r1_load = div64_u64(ppmu_load[PPMU_DDR_R1] * data->curr_freq[PPMU_MIF], data->max_freq[PPMU_MIF]); dmc_l_load = div64_u64(ppmu_load[PPMU_DDR_L] * data->curr_freq[PPMU_MIF], data->max_freq[PPMU_MIF]); data->load_history[PPMU_CPU][data->index] = cpu_load; data->load_history[PPMU_DDR_C][data->index] = dmc_c_load; data->load_history[PPMU_DDR_R1][data->index] = dmc_r1_load; data->load_history[PPMU_DDR_L][data->index++] = dmc_l_load; if (data->index >= LOAD_HISTORY_SIZE) data->index = 0; for (i = 0; i < LOAD_HISTORY_SIZE; i++) { cpu_load_average += data->load_history[PPMU_CPU][i]; dmc_c_load_average += data->load_history[PPMU_DDR_C][i]; dmc_r1_load_average += data->load_history[PPMU_DDR_R1][i]; dmc_l_load_average += data->load_history[PPMU_DDR_L][i]; } /* Calculate average Load */ cpu_load_average /= LOAD_HISTORY_SIZE; dmc_c_load_average /= LOAD_HISTORY_SIZE; dmc_r1_load_average /= LOAD_HISTORY_SIZE; dmc_l_load_average /= LOAD_HISTORY_SIZE; if (dmc_c_load >= dmc_r1_load) { dmc_load = dmc_c_load; dmc_load_average = dmc_c_load_average; } else { dmc_load = dmc_r1_load; dmc_load_average = dmc_r1_load_average; } if (dmc_l_load >= dmc_load) { dmc_load = dmc_l_load; dmc_load_average = dmc_l_load_average; } if (dmc_load >= DMC_MAX_THRESHOLD) { dmcfreq = data->max_freq[PPMU_MIF]; } else if (dmc_load < IDLE_THRESHOLD) { if (dmc_load_average < IDLE_THRESHOLD) dmcfreq = step_down(data, PPMU_MIF, 1); else dmcfreq = data->curr_freq[PPMU_MIF]; } else { if (dmc_load < dmc_load_average) { dmc_load = dmc_load_average; if (dmc_load >= DMC_MAX_THRESHOLD) dmc_load = DMC_MAX_THRESHOLD; } dmcfreq = div64_u64(data->max_freq[PPMU_MIF] * dmc_load, DMC_MAX_THRESHOLD); } lockfreq = dev_max_freq(data->dev[PPMU_MIF]); newfreq[PPMU_MIF] = max3(lockfreq, dmcfreq, cpufreq); opp[PPMU_MIF] = opp_find_freq_ceil(data->dev[PPMU_MIF], &newfreq[PPMU_MIF]); opp[PPMU_INT] = opp_find_freq_ceil(data->dev[PPMU_INT], &data->max_freq[PPMU_INT]); *mif_opp = opp[PPMU_MIF]; /* temporary */ *int_opp = opp[PPMU_INT]; }