Direct numerical simulations of turbulent boundary layers over longitudinal surface roughness are performed to investigate the impact of the surface roughness on the mean flow characteristics related to counter-rotating large-scale secondary flows. By systematically changing the two parameters of the pitch (P) and width (S) for roughness elements in the ranges of 0.57 <= P/delta <= 2.39 and 0.15 <= S/delta <= 1.12, where delta is the boundary layer thickness, we find that the size of the secondary flow in each case is mostly determined by the value of P - S, i.e., the valley width, over the ridge-type roughness. However, the strength of the secondary flows on the cross-stream plane relative to the flow is increased when the value of P increases or when the value of S decreases. In addition to the secondary flows, additional tertiary and quaternary flows are observed both above the roughness crest and in the valley as the values of P and S increase further. Based on an analysis using the turbulent kinetic energy transport equation, it is shown that the secondary flow over the ridge-type roughness is both driven and sustained by the anisotropy of turbulence, consistent with previous observations of a turbulent boundary layer over strip-type roughness [Anderson et al., J. Fluid Mech. 768, 316 (2015)]. Careful inspection of the turbulent kinetic energy budget reveals that the opposite rotational sense of the secondary flow between the ridge- and strip-type roughness elements is primarily attributed to the local imbalance of energy budget created by the strong turbulent transport term over the ridge-type roughness. The active transport of the kinetic energy over the ridge-type roughness is closely associated with the upward deflection of spanwise motions in the valley, mostly due to the roughness edge.